Skip to content

Commit

Permalink
Make testInstantTCPConnectionResetThrowsError more reliable (#2810)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzahrmalik authored Jul 25, 2024
1 parent 17b729f commit 2ef87d4
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit 2ef87d4

Please sign in to comment.