@@ -556,48 +556,46 @@ class HTTPClientTests: XCTestCase {
556
556
XCTAssertEqual ( 0 , progress. receivedBytes)
557
557
}
558
558
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)
564
562
}
565
563
}
566
564
567
- func testReadTimeout( ) throws {
565
+ func testReadTimeout( ) {
568
566
let localClient = HTTPClient ( eventLoopGroupProvider: . shared( self . clientGroup) ,
569
567
configuration: HTTPClient . Configuration ( timeout: HTTPClient . Configuration. Timeout ( read: . milliseconds( 150 ) ) ) )
570
568
571
569
defer {
572
570
XCTAssertNoThrow ( try localClient. syncShutdown ( ) )
573
571
}
574
572
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)
579
575
}
580
576
}
581
577
582
- func testConnectTimeout( ) throws {
578
+ func testConnectTimeout( ) {
583
579
let httpClient = HTTPClient ( eventLoopGroupProvider: . shared( self . clientGroup) ,
584
580
configuration: . init( timeout: . init( connect: . milliseconds( 100 ) , read: . milliseconds( 150 ) ) ) )
585
581
586
582
defer {
587
583
XCTAssertNoThrow ( try httpClient. syncShutdown ( ) )
588
584
}
589
585
590
- // 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 ( ) ) {
586
+ let localServer = HTTPBin ( )
587
+ let port = localServer. port
588
+ XCTAssertNoThrow { try localServer. shutdown ( ) }
589
+
590
+ // the server was just shutdown. there should be no way to connect to it right now.
591
+ XCTAssertThrowsError ( try httpClient. get ( url: " http://localhost: \( port) /get " ) . wait ( ) ) {
592
592
XCTAssertEqual ( $0 as? HTTPClientError , . connectTimeout)
593
593
}
594
594
}
595
595
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
- }
596
+ func testDeadline( ) {
597
+ XCTAssertThrowsError ( try self . defaultClient. get ( url: self . defaultHTTPBinURLPrefix + " wait " , deadline: . now( ) + . milliseconds( 150 ) ) . wait ( ) ) {
598
+ XCTAssertEqual ( $0 as? HTTPClientError , . readTimeout)
601
599
}
602
600
}
603
601
0 commit comments