Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 15 additions & 14 deletions Test/AwsCommonRuntimeKitTests/http/HTTP2ClientConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import XCTest
class HTTP2ClientConnectionTests: XCBaseTestCase {

let expectedVersion = HTTPVersion.version_2

let host = "postman-echo.com"

func testGetHTTP2RequestVersion() async throws {
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: "httpbin.org", alpnList: ["h2","http/1.1"])
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: host, alpnList: ["h2","http/1.1"])
let connection = try await connectionManager.acquireConnection()
XCTAssertEqual(connection.httpVersion, HTTPVersion.version_2)
}

// Test that the binding works not the actual functionality. C part has tests for functionality
func testHTTP2UpdateSetting() async throws {
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: "httpbin.org", alpnList: ["h2","http/1.1"])
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: host, alpnList: ["h2","http/1.1"])
let connection = try await connectionManager.acquireConnection()
if let connection = connection as? HTTP2ClientConnection {
try await connection.updateSetting(setting: HTTP2Settings(enablePush: false))
Expand All @@ -26,7 +27,7 @@ class HTTP2ClientConnectionTests: XCBaseTestCase {

// Test that the binding works not the actual functionality. C part has tests for functionality
func testHTTP2UpdateSettingEmpty() async throws {
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: "httpbin.org", alpnList: ["h2","http/1.1"])
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: host, alpnList: ["h2","http/1.1"])
let connection = try await connectionManager.acquireConnection()
if let connection = connection as? HTTP2ClientConnection {
try await connection.updateSetting(setting: HTTP2Settings())
Expand All @@ -37,7 +38,7 @@ class HTTP2ClientConnectionTests: XCBaseTestCase {

// Test that the binding works not the actual functionality. C part has tests for functionality
func testHTTP2SendPing() async throws {
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: "httpbin.org", alpnList: ["h2","http/1.1"])
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: host, alpnList: ["h2","http/1.1"])
let connection = try await connectionManager.acquireConnection()
if let connection = connection as? HTTP2ClientConnection {
var time = try await connection.sendPing()
Expand All @@ -51,7 +52,7 @@ class HTTP2ClientConnectionTests: XCBaseTestCase {

// Test that the binding works not the actual functionality. C part has tests for functionality
func testHTTP2SendGoAway() async throws {
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: "httpbin.org", alpnList: ["h2","http/1.1"])
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: host, alpnList: ["h2","http/1.1"])
let connection = try await connectionManager.acquireConnection()
if let connection = connection as? HTTP2ClientConnection {
connection.sendGoAway(error: .internalError, allowMoreStreams: false)
Expand All @@ -61,10 +62,10 @@ class HTTP2ClientConnectionTests: XCBaseTestCase {
}

func testGetHttpsRequest() async throws {
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: "httpbin.org", alpnList: ["h2","http/1.1"])
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: host, alpnList: ["h2","http/1.1"])
let response = try await HTTPClientTestFixture.sendHTTPRequest(
method: "GET",
endpoint: "httpbin.org",
endpoint: host,
path: "/get",
connectionManager: connectionManager,
expectedVersion: expectedVersion,
Expand All @@ -73,9 +74,9 @@ class HTTP2ClientConnectionTests: XCBaseTestCase {
XCTAssertEqual(response.headers[0].name, ":status")
let response2 = try await HTTPClientTestFixture.sendHTTPRequest(
method: "GET",
endpoint: "httpbin.org",
endpoint: host,
path: "/delete",
expectedStatus: 405,
expectedStatus: 404,
connectionManager: connectionManager,
expectedVersion: expectedVersion,
requestVersion: .version_2)
Expand All @@ -84,10 +85,10 @@ class HTTP2ClientConnectionTests: XCBaseTestCase {


func testGetHttpsRequestWithHTTP1_1Request() async throws {
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: "httpbin.org", alpnList: ["h2","http/1.1"])
let connectionManager = try await HTTPClientTestFixture.getHttpConnectionManager(endpoint: host, alpnList: ["h2","http/1.1"])
let response = try await HTTPClientTestFixture.sendHTTPRequest(
method: "GET",
endpoint: "httpbin.org",
endpoint: host,
path: "/get",
connectionManager: connectionManager,
expectedVersion: expectedVersion,
Expand All @@ -96,9 +97,9 @@ class HTTP2ClientConnectionTests: XCBaseTestCase {
XCTAssertEqual(response.headers[0].name, ":status")
let response2 = try await HTTPClientTestFixture.sendHTTPRequest(
method: "GET",
endpoint: "httpbin.org",
endpoint: host,
path: "/delete",
expectedStatus: 405,
expectedStatus: 404,
connectionManager: connectionManager,
expectedVersion: expectedVersion,
requestVersion: .version_1_1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import XCTest
class HTT2StreamManagerTests: XCBaseTestCase {
let endpoint = "d1cz66xoahf9cl.cloudfront.net"; // Use cloudfront for HTTP/2
let path = "/random_32_byte.data";

let host = "nghttp2.org"

func testStreamManagerCreate() throws {
let tlsContextOptions = TLSContextOptions()
let tlsContext = try TLSContext(options: tlsContextOptions, mode: .client)
Expand Down Expand Up @@ -106,7 +107,7 @@ class HTT2StreamManagerTests: XCBaseTestCase {
}

func testHTTP2StreamUpload() async throws {
let streamManager = try makeStreamManger(host: "nghttp2.org")
let streamManager = try makeStreamManger(host: host)
let semaphore = TestSemaphore(value: 0)
var httpResponse = HTTPResponse()
var onCompleteCalled = false
Expand Down Expand Up @@ -170,7 +171,7 @@ class HTT2StreamManagerTests: XCBaseTestCase {
}

func testHTTP2ParallelStreams(count: Int) async throws {
let streamManager = try makeStreamManger(host: "nghttp2.org")
let streamManager = try makeStreamManger(host: host)
return await withTaskGroup(of: Void.self) { taskGroup in
for _ in 1...count {
taskGroup.addTask {
Expand Down
20 changes: 18 additions & 2 deletions Test/AwsCommonRuntimeKitTests/io/StreamTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.
import XCTest
import Foundation

@testable import AwsCommonRuntimeKit

class StreamTests: XCBaseTestCase {
Expand All @@ -12,6 +13,13 @@ class StreamTests: XCBaseTestCase {
try testStream(iStreamCore: iStreamCore)
}

func testByteBufferEndOfStream() throws {
let data = "1234567890098765432112345678900987654321".data(using: .utf8)!
let byteBuffer = ByteBuffer(data: data[20...])
let iStreamCore = IStreamCore(iStreamable: byteBuffer)
try testStream(iStreamCore: iStreamCore)
}

func testStream(iStreamCore: IStreamCore) throws {

let capacity = 10
Expand All @@ -21,25 +29,30 @@ class StreamTests: XCBaseTestCase {
}

XCTAssertEqual(20, try iStreamCore.iStreamable.length())
XCTAssertFalse(iStreamCore.iStreamable.isEndOfStream())

var length = try iStreamCore.iStreamable.read(buffer: buffer)
XCTAssertEqual(length, capacity)
XCTAssertEqual(String(bytes: buffer, encoding: .utf8), "1234567890")
XCTAssertFalse(iStreamCore.iStreamable.isEndOfStream())

length = try iStreamCore.iStreamable.read(buffer: buffer)
XCTAssertEqual(length, capacity)
XCTAssertEqual(String(bytes: buffer, encoding: .utf8), "0987654321")
XCTAssertTrue(iStreamCore.iStreamable.isEndOfStream())

length = try iStreamCore.iStreamable.read(buffer: buffer)
XCTAssertEqual(length, nil)


try iStreamCore.iStreamable.seek(offset: 0, streamSeekType: StreamSeekType.begin)
XCTAssertFalse(iStreamCore.iStreamable.isEndOfStream())
length = try iStreamCore.iStreamable.read(buffer: buffer)
XCTAssertEqual(length, capacity)
XCTAssertEqual(String(bytes: buffer, encoding: .utf8), "1234567890")
XCTAssertFalse(iStreamCore.iStreamable.isEndOfStream())

try iStreamCore.iStreamable.seek(offset: 10, streamSeekType: StreamSeekType.begin)
XCTAssertFalse(iStreamCore.iStreamable.isEndOfStream())

let largeBuffer = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: 100)
defer {
Expand All @@ -49,12 +62,15 @@ class StreamTests: XCBaseTestCase {
length = try iStreamCore.iStreamable.read(buffer: largeBuffer)
XCTAssertEqual(length, capacity)
XCTAssertEqual(String(bytes: largeBuffer[..<length!], encoding: .utf8), "0987654321")
XCTAssertTrue(iStreamCore.iStreamable.isEndOfStream())

length = try iStreamCore.iStreamable.read(buffer: largeBuffer)
XCTAssertEqual(length, nil)

length = try iStreamCore.iStreamable.read(buffer: largeBuffer)
XCTAssertEqual(length, nil)

XCTAssertTrue(iStreamCore.iStreamable.isEndOfStream())
}

}
Loading