@@ -2038,6 +2038,7 @@ class HTTPClientTests: XCTestCase {
2038
2038
defer {
2039
2039
XCTAssertNoThrow ( try httpClient. syncShutdown ( ) )
2040
2040
XCTAssertNoThrow ( try httpServer. stop ( ) )
2041
+ XCTAssertNoThrow ( try elg. syncShutdownGracefully ( ) )
2041
2042
}
2042
2043
2043
2044
let delegate = TestDelegate ( eventLoop: second)
@@ -2069,10 +2070,17 @@ class HTTPClientTests: XCTestCase {
2069
2070
XCTAssertEqual ( error as! HTTPClientError , HTTPClientError . bodyLengthMismatch)
2070
2071
}
2071
2072
// Quickly try another request and check that it works.
2072
- var response = try self . defaultClient. get ( url: self . defaultHTTPBinURLPrefix + " get " ) . wait ( )
2073
- let info = try response. body!. readJSONDecodable ( RequestInfo . self, length: response. body!. readableBytes)
2074
- XCTAssertEqual ( info!. connectionNumber, 1 )
2075
- XCTAssertEqual ( info!. requestNumber, 1 )
2073
+ let response = try self . defaultClient. get ( url: self . defaultHTTPBinURLPrefix + " get " ) . wait ( )
2074
+ guard var body = response. body else {
2075
+ XCTFail ( " Body missing: \( response) " )
2076
+ return
2077
+ }
2078
+ guard let info = try body. readJSONDecodable ( RequestInfo . self, length: body. readableBytes) else {
2079
+ XCTFail ( " Cannot parse body: \( body. readableBytesView. map { $0 } ) " )
2080
+ return
2081
+ }
2082
+ XCTAssertEqual ( info. connectionNumber, 1 )
2083
+ XCTAssertEqual ( info. requestNumber, 1 )
2076
2084
}
2077
2085
2078
2086
// currently gets stuck because of #250 the server just never replies
@@ -2089,9 +2097,16 @@ class HTTPClientTests: XCTestCase {
2089
2097
}
2090
2098
// Quickly try another request and check that it works. If we by accident wrote some extra bytes into the
2091
2099
// stream (and reuse the connection) that could cause problems.
2092
- var response = try self . defaultClient. get ( url: self . defaultHTTPBinURLPrefix + " get " ) . wait ( )
2093
- let info = try response. body!. readJSONDecodable ( RequestInfo . self, length: response. body!. readableBytes)
2094
- XCTAssertEqual ( info!. connectionNumber, 1 )
2095
- XCTAssertEqual ( info!. requestNumber, 1 )
2100
+ let response = try self . defaultClient. get ( url: self . defaultHTTPBinURLPrefix + " get " ) . wait ( )
2101
+ guard var body = response. body else {
2102
+ XCTFail ( " Body missing: \( response) " )
2103
+ return
2104
+ }
2105
+ guard let info = try body. readJSONDecodable ( RequestInfo . self, length: body. readableBytes) else {
2106
+ XCTFail ( " Cannot parse body: \( body. readableBytesView. map { $0 } ) " )
2107
+ return
2108
+ }
2109
+ XCTAssertEqual ( info. connectionNumber, 1 )
2110
+ XCTAssertEqual ( info. requestNumber, 1 )
2096
2111
}
2097
2112
}
0 commit comments