Skip to content

Improve HTTPClient tests #424

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
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
28 changes: 11 additions & 17 deletions Tests/AsyncHTTPClientTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,30 +556,26 @@ class HTTPClientTests: XCTestCase {
XCTAssertEqual(0, progress.receivedBytes)
}

func testRemoteClose() throws {
XCTAssertThrowsError(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "close").wait(), "Should fail") { error in
guard case let error = error as? HTTPClientError, error == .remoteConnectionClosed else {
return XCTFail("Should fail with remoteConnectionClosed")
}
func testRemoteClose() {
XCTAssertThrowsError(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "close").wait()) {
XCTAssertEqual($0 as? HTTPClientError, .remoteConnectionClosed)
}
}

func testReadTimeout() throws {
func testReadTimeout() {
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: HTTPClient.Configuration(timeout: HTTPClient.Configuration.Timeout(read: .milliseconds(150))))

defer {
XCTAssertNoThrow(try localClient.syncShutdown())
}

XCTAssertThrowsError(try localClient.get(url: self.defaultHTTPBinURLPrefix + "wait").wait(), "Should fail") { error in
guard case let error = error as? HTTPClientError, error == .readTimeout else {
return XCTFail("Should fail with readTimeout")
}
XCTAssertThrowsError(try localClient.get(url: self.defaultHTTPBinURLPrefix + "wait").wait()) {
XCTAssertEqual($0 as? HTTPClientError, .readTimeout)
}
}

func testConnectTimeout() throws {
func testConnectTimeout() {
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: .init(timeout: .init(connect: .milliseconds(100), read: .milliseconds(150))))

Expand All @@ -588,16 +584,14 @@ class HTTPClientTests: XCTestCase {
}

// This must throw as 198.51.100.254 is reserved for documentation only
XCTAssertThrowsError(try httpClient.get(url: "http://198.51.100.254:65535/get").wait()) {
XCTAssertThrowsError(try httpClient.get(url: "http://198.51.100.254/get").wait()) {
XCTAssertEqual($0 as? HTTPClientError, .connectTimeout)
}
}

func testDeadline() throws {
XCTAssertThrowsError(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "wait", deadline: .now() + .milliseconds(150)).wait(), "Should fail") { error in
guard case let error = error as? HTTPClientError, error == .readTimeout else {
return XCTFail("Should fail with readTimeout")
}
func testDeadline() {
XCTAssertThrowsError(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "wait", deadline: .now() + .milliseconds(150)).wait()) {
XCTAssertEqual($0 as? HTTPClientError, .readTimeout)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting a readTimeout error on a deadline is weird. This will be actually fixed with the new implementation

}
}

Expand Down