fix two potential hangs in the test suite (#1240)

Motivation:

There were at least 2 tests in our test suite that were racing EventLoop
shutdown.

Modifications:

Don't race EL shutdown.

Result:

More reliable test suite.
This commit is contained in:
Johannes Weiss authored and Cory Benfield committed 2019-11-13 14:14:15 +00:00
1 parent 1c160afa95
commit 0fe0ceca11
2 files changed
+10 -5

No files matched your search

+5 -4
View File
@@ -577,8 +577,11 @@ class EchoServerClientTest : XCTestCase {
func testPendingReadProcessedAfterWriteError() throws {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let dpGroup = DispatchGroup()
defer {
XCTAssertNoThrow(try group.syncShutdownGracefully())
}
let dpGroup = DispatchGroup()
dpGroup.enter()
let str = "hi there"
@@ -597,7 +600,7 @@ class EchoServerClientTest : XCTestCase {
}
private func writeUntilFailed(_ context: ChannelHandlerContext, _ buffer: ByteBuffer) {
context.writeAndFlush(NIOAny(buffer)).whenComplete { (_: Result<Void, Error>) in
context.writeAndFlush(NIOAny(buffer)).whenSuccess {
context.eventLoop.execute {
self.writeUntilFailed(context, buffer)
}
@@ -665,8 +668,6 @@ class EchoServerClientTest : XCTestCase {
completeBuffer.writeString(str)
try countingHandler.assertReceived(buffer: completeBuffer)
XCTAssertNoThrow(try group.syncShutdownGracefully())
}
func testChannelErrorEOFNotFiredThroughPipeline() throws {
+5 -1
View File
@@ -605,12 +605,16 @@ public final class EventLoopTest : XCTestCase {
channel.connect(to: serverSocket.localAddress!)
}
}.wait() as Void)
let closeFutureFulfilledEventually = Atomic<Bool>(value: false)
XCTAssertFalse(channel.closeFuture.isFulfilled)
channel.closeFuture.whenSuccess {
XCTAssertTrue(closeFutureFulfilledEventually.compareAndExchange(expected: false, desired: true))
}
XCTAssertNoThrow(try group.syncShutdownGracefully())
XCTAssertTrue(assertHandler.groupIsShutdown.compareAndExchange(expected: false, desired: true))
XCTAssertTrue(assertHandler.removed.load())
XCTAssertTrue(channel.closeFuture.isFulfilled)
XCTAssertFalse(channel.isActive)
XCTAssertTrue(closeFutureFulfilledEventually.load())
}
public func testScheduleMultipleTasks() throws {