diff --git a/IntegrationTests/AWSIntegrationTestUtils/ConcurrentTestHelper.swift b/IntegrationTests/AWSIntegrationTestUtils/ConcurrentTestHelper.swift new file mode 100644 index 00000000000..19b461b2926 --- /dev/null +++ b/IntegrationTests/AWSIntegrationTestUtils/ConcurrentTestHelper.swift @@ -0,0 +1,49 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +/// Runs a test concurrently for the number of times specified +/// +/// The test is run repeatedly using a Swift task group; each test run is performed as a "child task". +/// The function returns when all test runs have completed, and rethrows if a test run throws. +/// - Parameters: +/// - count: The number of test runs +/// - test: The function pointer for the test to run +/// - Throws: Any error thrown by one of the test runs. +public func repeatConcurrently(count: Int, test: @escaping () async throws -> Void) async throws { + try await withThrowingTaskGroup(of: Void.self) { taskGroup in + for _ in 0.. Void, + args: Any... +) async throws { + try await withThrowingTaskGroup(of: Void.self) { taskGroup in + for _ in 0.. Data { + let segmentData = Data("1234567890".utf8) + var wholeData = Data() + for _ in 0..<(Int(numMegabytes)/10) { + wholeData.append(segmentData) + } + return wholeData + } + + // Puts data to S3, gets the uploaded file, then asserts retrieved data equals original data + func getObject(args: Any...) async throws { + guard let data = args[0] as? Data else { + throw ClientError.dataNotFound("Failed to retrieve dummy data.") + } + let file = ByteStream.data(data) + let objectKey = UUID().uuidString.split(separator: "-").first!.lowercased() + let putObjectInput = PutObjectInput(body: file, bucket: bucketName, key: objectKey) + _ = try await client.putObject(input: putObjectInput) + let retrievedData = try await client.getObject(input: GetObjectInput( + bucket: bucketName, key: objectKey + )).body?.readData() + XCTAssertEqual(data, retrievedData) + } +}