Skip to content

Commit b3583ba

Browse files
authored
Fix flaky Network.framework testConnectionFailError test (#600)
we may recieve a posix `ECONNREFUSED` too
1 parent 794dc9d commit b3583ba

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class HTTPClientNIOTSTests: XCTestCase {
104104

105105
func testConnectionFailError() {
106106
guard isTestingNIOTS() else { return }
107+
#if canImport(Network)
107108
let httpBin = HTTPBin(.http1_1(ssl: false))
108109
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
109110
configuration: .init(timeout: .init(connect: .milliseconds(100),
@@ -117,8 +118,15 @@ class HTTPClientNIOTSTests: XCTestCase {
117118
XCTAssertNoThrow(try httpBin.shutdown())
118119

119120
XCTAssertThrowsError(try httpClient.get(url: "http://localhost:\(port)/get").wait()) {
120-
XCTAssertEqual($0 as? HTTPClientError, .connectTimeout)
121+
if let httpClientError = $0 as? HTTPClientError {
122+
XCTAssertEqual(httpClientError, .connectTimeout)
123+
} else if let posixError = $0 as? HTTPClient.NWPOSIXError {
124+
XCTAssertEqual(posixError.errorCode, .ECONNREFUSED)
125+
} else {
126+
XCTFail("unexpected error \($0)")
127+
}
121128
}
129+
#endif
122130
}
123131

124132
func testTLSVersionError() {

0 commit comments

Comments
 (0)