Skip to content

Commit 70af540

Browse files
committed
Address flakiness of testSSLHandshakeErrorPropagation
Motivation: Flaky tests are bad. This test is flaky because the server closes the connection immediately upon channelActive. In practice this can mean that the handshake never even gets a chance to start: by the time the SSLHandler ends up in the pipeline the connection is already dead. Heck, by the time we attempt to complete the connection the connection might be dead. Modifications: - Change the shutdown to be on first read. - Remove the disabled autoRead. - Change the expected NIOTS failure mode to connectTimeout, which is how this manifests in NIOTS. Result: Test is no longer flaky.
1 parent 9671de7 commit 70af540

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+11-4
Original file line numberDiff line numberDiff line change
@@ -2680,13 +2680,12 @@ class HTTPClientTests: XCTestCase {
26802680
class CloseHandler: ChannelInboundHandler {
26812681
typealias InboundIn = Any
26822682

2683-
func channelActive(context: ChannelHandlerContext) {
2683+
func channelRead(context: ChannelHandlerContext) {
26842684
context.close(promise: nil)
26852685
}
26862686
}
26872687

26882688
let server = try ServerBootstrap(group: self.serverGroup)
2689-
.childChannelOption(ChannelOptions.autoRead, value: false)
26902689
.childChannelInitializer { channel in
26912690
channel.pipeline.addHandler(CloseHandler())
26922691
}
@@ -2697,15 +2696,23 @@ class HTTPClientTests: XCTestCase {
26972696
XCTAssertNoThrow(try server.close().wait())
26982697
}
26992698

2699+
// We set the connect timeout down very low here because on NIOTS this manifests as a connect
2700+
// timeout.
2701+
let config = HTTPClient.Configuration(timeout: HTTPClient.Configuration.Timeout(connect: .milliseconds(100), read: nil))
2702+
let client = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup), configuration: config)
2703+
defer {
2704+
XCTAssertNoThrow(try client.syncShutdown())
2705+
}
2706+
27002707
let request = try Request(url: "https://localhost:\(server.localAddress!.port!)", method: .GET)
2701-
let task = self.defaultClient.execute(request: request, delegate: TestHTTPDelegate())
2708+
let task = client.execute(request: request, delegate: TestHTTPDelegate())
27022709

27032710
XCTAssertThrowsError(try task.wait()) { error in
27042711
#if os(Linux)
27052712
XCTAssertEqual(error as? NIOSSLError, NIOSSLError.uncleanShutdown)
27062713
#else
27072714
if isTestingNIOTS() {
2708-
XCTAssertEqual((error as? AsyncHTTPClient.HTTPClient.NWTLSError).map { $0.status }, errSSLClosedNoNotify)
2715+
XCTAssertEqual((error as? ChannelError), .connectTimeout(.milliseconds(100)))
27092716
} else {
27102717
XCTAssertEqual((error as? IOError).map { $0.errnoCode }, 54)
27112718
}

0 commit comments

Comments
 (0)