@@ -5,10 +5,11 @@ import XCTest
55
66@testable import AwsCommonRuntimeKit
77
8- class HTT2StreamManagerTests : XCBaseTestCase {
8+ class HTTP2StreamManagerTests : XCBaseTestCase {
99 let endpoint = " d1cz66xoahf9cl.cloudfront.net " // Use cloudfront for HTTP/2
1010 let path = " /random_32_byte.data "
11- let host = " nghttp2.org "
11+ let host = " localhost "
12+ let port = 3443
1213
1314 func testStreamManagerCreate( ) throws {
1415 let tlsContextOptions = TLSContextOptions ( )
@@ -26,7 +27,7 @@ class HTT2StreamManagerTests: XCBaseTestCase {
2627 hostName: endpoint,
2728 port: port,
2829 maxConnections: 30 ,
29- proxyOptions: HTTPProxyOptions ( hostName: " localhost " , port: 80 ) ,
30+ proxyOptions: HTTPProxyOptions ( hostName: host , port: 80 ) ,
3031 proxyEnvSettings: HTTPProxyEnvSettings ( proxyConnectionType: HTTPProxyConnectionType . forward) ,
3132 socketOptions: SocketOptions ( socketType: . stream) ,
3233 tlsOptions: tlsConnectionOptions,
@@ -75,6 +76,7 @@ class HTT2StreamManagerTests: XCBaseTestCase {
7576 func makeStreamManger( host: String , port: Int = 443 ) throws -> HTTP2StreamManager {
7677 let tlsContextOptions = TLSContextOptions ( )
7778 tlsContextOptions. setAlpnList ( [ " h2 " ] )
79+ tlsContextOptions. setVerifyPeer ( false )
7880 let tlsContext = try TLSContext ( options: tlsContextOptions, mode: . client)
7981
8082 var tlsConnectionOptions = TLSConnectionOptions ( context: tlsContext)
@@ -89,7 +91,6 @@ class HTT2StreamManagerTests: XCBaseTestCase {
8991 hostResolver: hostResolver)
9092
9193 let socketOptions = SocketOptions ( socketType: . stream)
92- let port = UInt32 ( 443 )
9394 let streamManager = try HTTP2StreamManager (
9495 options: HTTP2StreamManagerOptions (
9596 clientBootstrap: bootstrap,
@@ -112,15 +113,16 @@ class HTT2StreamManagerTests: XCBaseTestCase {
112113 }
113114
114115 func testHTTP2StreamUpload( ) async throws {
115- let streamManager = try makeStreamManger ( host: host)
116+ try skipIfLocalhostUnavailable ( )
117+ let streamManager = try makeStreamManger ( host: host, port: port)
116118 let semaphore = TestSemaphore ( value: 0 )
117119 var httpResponse = HTTPResponse ( )
118120 var onCompleteCalled = false
119121 let testBody = " testBody "
120122 let http2RequestOptions = try HTTPClientTestFixture . getHTTP2RequestOptions (
121123 method: " PUT " ,
122- path: " /httpbin/put " ,
123- authority: " nghttp2.org " ,
124+ path: " /echo " ,
125+ authority: host ,
124126 body: testBody,
125127 response: & httpResponse,
126128 semaphore: semaphore,
@@ -150,38 +152,40 @@ class HTT2StreamManagerTests: XCBaseTestCase {
150152 XCTAssertNil ( httpResponse. error)
151153 XCTAssertEqual ( httpResponse. statusCode, 200 )
152154
153- // Parse json body
155+ // Parse json body - localhost echo server returns {"body": "...", "bytes": N}
154156 struct Response : Codable {
155- let data : String
157+ let body : String
156158 }
157159
158160 let body : Response = try ! JSONDecoder ( ) . decode ( Response . self, from: httpResponse. body)
159- XCTAssertEqual ( body. data , testBody + HTTPClientTestFixture. TEST_DOC_LINE)
161+ XCTAssertEqual ( body. body , testBody + HTTPClientTestFixture. TEST_DOC_LINE)
160162 }
161163
162164 // Test that the binding works not the actual functionality. C part has tests for functionality
163165 func testHTTP2StreamReset( ) async throws {
166+ try skipIfLocalhostUnavailable ( )
164167 let streamManager = try makeStreamManger ( host: endpoint)
165168 let http2RequestOptions = try HTTPClientTestFixture . getHTTP2RequestOptions (
166169 method: " PUT " ,
167- path: " /httpbin/put " ,
168- authority: " nghttp2.org " )
170+ path: " /echo " ,
171+ authority: host )
169172
170173 let stream = try await streamManager. acquireStream ( requestOptions: http2RequestOptions)
171174 try stream. resetStream ( error: HTTP2Error . internalError)
172175 }
173176
174177 func testHTTP2ParallelStreams( ) async throws {
178+ try skipIfLocalhostUnavailable ( )
175179 try await testHTTP2ParallelStreams ( count: 10 )
176180 }
177181
178182 func testHTTP2ParallelStreams( count: Int ) async throws {
179- let streamManager = try makeStreamManger ( host: host)
183+ let streamManager = try makeStreamManger ( host: host, port : port )
180184 return await withTaskGroup ( of: Void . self) { taskGroup in
181185 for _ in 1 ... count {
182186 taskGroup. addTask {
183187 _ = try ! await HTTPClientTestFixture . sendHTTP2Request (
184- method: " GET " , path: " /httpbin/get " , authority: " nghttp2.org " ,
188+ method: " GET " , path: " /echo " , authority: " localhost " ,
185189 streamManager: streamManager)
186190 }
187191 }
0 commit comments