Skip to content

[HTTP2] Read Timeout Integration Test #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tests/AsyncHTTPClientTests/HTTP2ClientTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension HTTP2ClientTests {
("testConcurrentRequestsWorkWithRequiredEventLoop", testConcurrentRequestsWorkWithRequiredEventLoop),
("testUncleanShutdownCancelsExecutingAndQueuedTasks", testUncleanShutdownCancelsExecutingAndQueuedTasks),
("testCancelingRunningRequest", testCancelingRunningRequest),
("testReadTimeout", testReadTimeout),
("testStressCancelingRunningRequestFromDifferentThreads", testStressCancelingRunningRequestFromDifferentThreads),
("testPlatformConnectErrorIsForwardedOnTimeout", testPlatformConnectErrorIsForwardedOnTimeout),
]
Expand Down
22 changes: 22 additions & 0 deletions Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,28 @@ class HTTP2ClientTests: XCTestCase {
}
}

func testReadTimeout() {
let bin = HTTPBin(.http2(compress: false)) { _ in SendHeaderAndWaitChannelHandler() }
defer { XCTAssertNoThrow(try bin.shutdown()) }
var config = HTTPClient.Configuration()
var tlsConfig = TLSConfiguration.makeClientConfiguration()
tlsConfig.certificateVerification = .none
config.tlsConfiguration = tlsConfig
config.httpVersion = .automatic
config.timeout.read = .milliseconds(100)
let client = HTTPClient(
eventLoopGroupProvider: .createNew,
configuration: config,
backgroundActivityLogger: Logger(label: "HTTPClient", factory: StreamLogHandler.standardOutput(label:))
)
defer { XCTAssertNoThrow(try client.syncShutdown()) }

let response = client.get(url: "https://localhost:\(bin.port)")
XCTAssertThrowsError(try response.timeout(after: .seconds(2)).wait()) { error in
XCTAssertEqual(error as? HTTPClientError, .readTimeout)
}
}

func testStressCancelingRunningRequestFromDifferentThreads() {
let bin = HTTPBin(.http2(compress: false)) { _ in SendHeaderAndWaitChannelHandler() }
defer { XCTAssertNoThrow(try bin.shutdown()) }
Expand Down