Skip to content

Commit eab5966

Browse files
committed
test read timeout
1 parent 3e44e51 commit eab5966

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Tests/AsyncHTTPClientTests/HTTP2ClientTests+XCTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension HTTP2ClientTests {
3131
("testConcurrentRequestsWorkWithRequiredEventLoop", testConcurrentRequestsWorkWithRequiredEventLoop),
3232
("testUncleanShutdownCancelsExecutingAndQueuedTasks", testUncleanShutdownCancelsExecutingAndQueuedTasks),
3333
("testCancelingRunningRequest", testCancelingRunningRequest),
34+
("testReadTimeout", testReadTimeout),
3435
("testStressCancelingRunningRequestFromDifferentThreads", testStressCancelingRunningRequestFromDifferentThreads),
3536
("testPlatformConnectErrorIsForwardedOnTimeout", testPlatformConnectErrorIsForwardedOnTimeout),
3637
]

Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ class HTTP2ClientTests: XCTestCase {
259259
}
260260
}
261261

262+
func testReadTimeout() {
263+
let bin = HTTPBin(.http2(compress: false)) { _ in SendHeaderAndWaitChannelHandler() }
264+
defer { XCTAssertNoThrow(try bin.shutdown()) }
265+
var config = HTTPClient.Configuration()
266+
var tlsConfig = TLSConfiguration.makeClientConfiguration()
267+
tlsConfig.certificateVerification = .none
268+
config.tlsConfiguration = tlsConfig
269+
config.timeout.read = .milliseconds(100)
270+
let client = HTTPClient(
271+
eventLoopGroupProvider: .createNew,
272+
configuration: config,
273+
backgroundActivityLogger: Logger(label: "HTTPClient", factory: StreamLogHandler.standardOutput(label:))
274+
)
275+
defer { XCTAssertNoThrow(try client.syncShutdown()) }
276+
277+
let response = client.get(url: "https://localhost:\(bin.port)")
278+
XCTAssertThrowsError(try response.timeout(after: .seconds(2)).wait()) { error in
279+
XCTAssertEqual(error as? HTTPClientError, .readTimeout)
280+
}
281+
}
282+
262283
func testStressCancelingRunningRequestFromDifferentThreads() {
263284
let bin = HTTPBin(.http2(compress: false)) { _ in SendHeaderAndWaitChannelHandler() }
264285
defer { XCTAssertNoThrow(try bin.shutdown()) }

0 commit comments

Comments
 (0)