Skip to content

Commit 10fff8d

Browse files
committed
Improve HTTPClient tests
1 parent ed58449 commit 10fff8d

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+11-17
Original file line numberDiff line numberDiff line change
@@ -556,30 +556,26 @@ class HTTPClientTests: XCTestCase {
556556
XCTAssertEqual(0, progress.receivedBytes)
557557
}
558558

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

567-
func testReadTimeout() throws {
565+
func testReadTimeout() {
568566
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
569567
configuration: HTTPClient.Configuration(timeout: HTTPClient.Configuration.Timeout(read: .milliseconds(150))))
570568

571569
defer {
572570
XCTAssertNoThrow(try localClient.syncShutdown())
573571
}
574572

575-
XCTAssertThrowsError(try localClient.get(url: self.defaultHTTPBinURLPrefix + "wait").wait(), "Should fail") { error in
576-
guard case let error = error as? HTTPClientError, error == .readTimeout else {
577-
return XCTFail("Should fail with readTimeout")
578-
}
573+
XCTAssertThrowsError(try localClient.get(url: self.defaultHTTPBinURLPrefix + "wait").wait()) {
574+
XCTAssertEqual($0 as? HTTPClientError, .readTimeout)
579575
}
580576
}
581577

582-
func testConnectTimeout() throws {
578+
func testConnectTimeout() {
583579
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
584580
configuration: .init(timeout: .init(connect: .milliseconds(100), read: .milliseconds(150))))
585581

@@ -588,16 +584,14 @@ class HTTPClientTests: XCTestCase {
588584
}
589585

590586
// This must throw as 198.51.100.254 is reserved for documentation only
591-
XCTAssertThrowsError(try httpClient.get(url: "http://198.51.100.254:65535/get").wait()) {
587+
XCTAssertThrowsError(try httpClient.get(url: "http://198.51.100.254:\(port)/get").wait()) {
592588
XCTAssertEqual($0 as? HTTPClientError, .connectTimeout)
593589
}
594590
}
595591

596-
func testDeadline() throws {
597-
XCTAssertThrowsError(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "wait", deadline: .now() + .milliseconds(150)).wait(), "Should fail") { error in
598-
guard case let error = error as? HTTPClientError, error == .readTimeout else {
599-
return XCTFail("Should fail with readTimeout")
600-
}
592+
func testDeadline() {
593+
XCTAssertThrowsError(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "wait", deadline: .now() + .milliseconds(150)).wait()) {
594+
XCTAssertEqual($0 as? HTTPClientError, .readTimeout)
601595
}
602596
}
603597

0 commit comments

Comments
 (0)