Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make testInstantTCPConnectionResetThrowsError more reliable #2810

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Tests/NIOPosixTests/SocketChannelTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ public final class SocketChannelTest: XCTestCase {
#if !os(Linux) && !os(Android)
// This test checks that we correctly fail with an error rather than
// asserting or silently ignoring if a client aborts the connection
// early with a RST during or immediately after accept().
// early with a RST before accept(). The behaviour is the same as closing the socket
// during the accept. But it is easier to test closing the socket before the accept, than during it.
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer { XCTAssertNoThrow(try group.syncShutdownGracefully()) }

Expand Down Expand Up @@ -660,8 +661,13 @@ public final class SocketChannelTest: XCTestCase {
XCTAssertNoThrow(try clientSocket.connect(to: serverChannel.localAddress!))
XCTAssertNoThrow(try clientSocket.close())

// Trigger accept() in the server
serverChannel.read()
// We wait here to allow slow machines to close the socket
// We want to ensure the socket is closed before we trigger accept
// That will trigger the error that we want to test for
group.any().scheduleTask(in: .seconds(1)) {
// Trigger accept() in the server
serverChannel.read()
}

// Wait for the server to have something
XCTAssertThrowsError(try serverPromise.futureResult.wait()) { error in
Expand Down