-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathS3ConcurrentTests.swift
57 lines (46 loc) · 2.07 KB
/
S3ConcurrentTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import Foundation
import Smithy
import SmithyStreams
import XCTest
import AWSS3
import AWSIntegrationTestUtils
final class S3ConcurrentTests: S3XCTestCase, @unchecked Sendable {
private var fileData: Data!
// Payload just below chunked threshold
// Tests concurrent upload of simple data payloads
func test_10x_1MB_getObject() async throws {
fileData = generateRandomTextData(ofSizeInMB: 1)
try await repeatConcurrentlyWithArgs(count: 10, test: getObject, arg: fileData!)
}
// Payload at chunked threshold, just large enough to chunk
// Tests concurrent upload with aws-chunked encoding & flexible checksums
func test_10x_1_5MB_getObject() async throws {
fileData = generateRandomTextData(ofSizeInMB: 1.5)
try await repeatConcurrentlyWithArgs(count: 10, test: getObject, arg: fileData!)
}
// Payload 256 bytes with 200 concurrent requests, sends as simple data
// Tests very high concurrency with small data payloads
func test_200x_256B_getObject() async throws {
fileData = generateRandomTextData(ofSizeInBytes: 256)
try await repeatConcurrentlyWithArgs(count: 200, test: getObject, arg: fileData!)
}
// MARK: - Private methods
// Puts data to S3, gets the uploaded file, asserts retrieved data == original data, deletes S3 object
private func getObject(data: Data) async throws {
let objectKey = UUID().uuidString.split(separator: "-").first!.lowercased()
let putObjectInput = PutObjectInput(body: .data(data), 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)
let deleteObjectInput = DeleteObjectInput(bucket: bucketName, key: objectKey)
_ = try await client.deleteObject(input: deleteObjectInput)
}
}