Skip to content

Commit 164169a

Browse files
authored
[HTTP2] Read Timeout Integration Test (#474)
1 parent 3e44e51 commit 164169a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Diff for: Tests/AsyncHTTPClientTests/HTTP2ClientTests+XCTest.swift

+1
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
]

Diff for: Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift

+22
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ 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.httpVersion = .automatic
270+
config.timeout.read = .milliseconds(100)
271+
let client = HTTPClient(
272+
eventLoopGroupProvider: .createNew,
273+
configuration: config,
274+
backgroundActivityLogger: Logger(label: "HTTPClient", factory: StreamLogHandler.standardOutput(label:))
275+
)
276+
defer { XCTAssertNoThrow(try client.syncShutdown()) }
277+
278+
let response = client.get(url: "https://localhost:\(bin.port)")
279+
XCTAssertThrowsError(try response.timeout(after: .seconds(2)).wait()) { error in
280+
XCTAssertEqual(error as? HTTPClientError, .readTimeout)
281+
}
282+
}
283+
262284
func testStressCancelingRunningRequestFromDifferentThreads() {
263285
let bin = HTTPBin(.http2(compress: false)) { _ in SendHeaderAndWaitChannelHandler() }
264286
defer { XCTAssertNoThrow(try bin.shutdown()) }

0 commit comments

Comments
 (0)