Files
swift-nio/Tests/NIOTests/BootstrapTest.swift
T
Johannes Weiss 6bf4f19ffe better diagnostics for flaky tests (#512)
Motivation:

We have a few flaky tests, namely:

- testWriteOnAccept (#510)
- testBootstrapsCallInitializersOnCorrectEventLoop (#449)
- testCloseFutureNotifiedBeforeUnblock (#440)
- testFailedRegistrationOfAcceptedSocket (#439)
- testPortNumbers (#429)
- testPendingReadProcessedAfterWriteError (#246)

and we should make them non-flaky. First step to achieve this is better
diagnostics and this is what this patch is trying to deliver.

Modifications:

improve flaky tests' diagnostics

Result:

hopefully we can soon make them non-flaky.
2018-07-13 12:26:57 +01:00

62 lines
2.6 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import NIO
import XCTest
class BootstrapTest: XCTestCase {
func testBootstrapsCallInitializersOnCorrectEventLoop() throws {
for numThreads in [1 /* everything on one event loop */,
2 /* some stuff has shared event loops */,
5 /* everything on a different event loop */] {
let group = MultiThreadedEventLoopGroup(numberOfThreads: numThreads)
defer {
XCTAssertNoThrow(try group.syncShutdownGracefully())
}
let childChannelDone: EventLoopPromise<Void> = group.next().newPromise()
let serverChannelDone: EventLoopPromise<Void> = group.next().newPromise()
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
.childChannelInitializer { channel in
XCTAssert(channel.eventLoop.inEventLoop)
childChannelDone.succeed(result: ())
return channel.eventLoop.newSucceededFuture(result: ())
}
.serverChannelInitializer { channel in
XCTAssert(channel.eventLoop.inEventLoop)
serverChannelDone.succeed(result: ())
return channel.eventLoop.newSucceededFuture(result: ())
}
.bind(host: "localhost", port: 0)
.wait())
defer {
XCTAssertNoThrow(try serverChannel.close().wait())
}
let client = try assertNoThrowWithValue(ClientBootstrap(group: group)
.channelInitializer { channel in
XCTAssert(channel.eventLoop.inEventLoop)
return channel.eventLoop.newSucceededFuture(result: ())
}
.connect(to: serverChannel.localAddress!)
.wait())
defer {
XCTAssertNoThrow(try client.syncCloseAcceptingAlreadyClosed())
}
XCTAssertNoThrow(try childChannelDone.futureResult.wait())
XCTAssertNoThrow(try serverChannelDone.futureResult.wait())
}
}
}