diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginAccelerateIntegrationTests.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginAccelerateIntegrationTests.swift index 937a239daf..c96cb9d0a1 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginAccelerateIntegrationTests.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginAccelerateIntegrationTests.swift @@ -25,8 +25,10 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase { let task = Amplify.Storage.uploadData(key: key, data: data, options: .init(pluginOptions:["useAccelerateEndpoint": useAccelerateEndpoint])) - _ = try await task.value - try await Amplify.Storage.remove(key: key) + await waitTasks(timeout: 5) { + _ = try await task.value + try await Amplify.Storage.remove(key: key) + } } /// Given: A data object. @@ -35,15 +37,17 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase { func testUploadDataWithAccelerateDisabledExplicitlyToWrongType() async throws { let key = UUID().uuidString let data = Data(key.utf8) - do { - let task = Amplify.Storage.uploadData(key: key, - data: data, - options: .init(pluginOptions:["useAccelerateEndpoint": "false"])) - _ = try await task.value - XCTFail("Expecting error from bogus useAccelerateEndpoint value type (String)") - try await Amplify.Storage.remove(key: key) - } catch { - XCTAssertNotNil(error) + await waitTasks(timeout: 5) { + do { + let task = Amplify.Storage.uploadData(key: key, + data: data, + options: .init(pluginOptions:["useAccelerateEndpoint": "false"])) + _ = try await task.value + XCTFail("Expecting error from bogus useAccelerateEndpoint value type (String)") + try await Amplify.Storage.remove(key: key) + } catch { + XCTAssertNotNil(error) + } } } @@ -63,8 +67,10 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase { let task = Amplify.Storage.uploadFile(key: key, local: fileURL, options: .init(pluginOptions:["useAccelerateEndpoint": useAccelerateEndpoint])) - _ = try await task.value - try await Amplify.Storage.remove(key: key) + await waitTasks(timeout: 5) { + _ = try await task.value + try await Amplify.Storage.remove(key: key) + } } /// Given: A large data object. @@ -75,8 +81,10 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase { let task = Amplify.Storage.uploadData(key: key, data: AWSS3StoragePluginTestBase.largeDataObject, options: .init(pluginOptions:["useAccelerateEndpoint": useAccelerateEndpoint])) - _ = try await task.value - try await Amplify.Storage.remove(key: key) + await waitTasks(timeout: 15) { + _ = try await task.value + try await Amplify.Storage.remove(key: key) + } } /// Given: An object in storage. diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift index d8afa47f97..1a8f462a98 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift @@ -201,7 +201,9 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { let fileURL = URL(fileURLWithPath: filePath) removeIfExists(fileURL) - _ = try await Amplify.Storage.downloadFile(key: key, local: fileURL, options: .init()).value + await waitTasks(timeout: 20) { + _ = try await Amplify.Storage.downloadFile(key: key, local: fileURL, options: .init()).value + } let fileExists = FileManager.default.fileExists(atPath: fileURL.path) XCTAssertTrue(fileExists) diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginListObjectsIntegrationTests.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginListObjectsIntegrationTests.swift index 998460200f..0a7f203452 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginListObjectsIntegrationTests.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginListObjectsIntegrationTests.swift @@ -24,7 +24,9 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase let data = Data(key.utf8) let uniqueStringPath = "public/\(key)" - _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value + } let firstListResult = try await Amplify.Storage.list(path: .fromString(uniqueStringPath)) @@ -56,13 +58,15 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase // Sign in _ = try await Amplify.Auth.signIn(username: Self.user1, password: Self.password) - _ = try await Amplify.Storage.uploadData( - path: .fromIdentityID({ identityId in - uniqueStringPath = "protected/\(identityId)/\(key)" - return uniqueStringPath + "test1" - }), - data: data, - options: nil).value + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadData( + path: .fromIdentityID({ identityId in + uniqueStringPath = "protected/\(identityId)/\(key)" + return uniqueStringPath + "test1" + }), + data: data, + options: nil).value + } let firstListResult = try await Amplify.Storage.list(path: .fromString(uniqueStringPath)) @@ -101,13 +105,15 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase // Sign in _ = try await Amplify.Auth.signIn(username: Self.user1, password: Self.password) - _ = try await Amplify.Storage.uploadData( - path: .fromIdentityID({ identityId in - uniqueStringPath = "private/\(identityId)/\(key)" - return uniqueStringPath + "test1" - }), - data: data, - options: nil).value + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadData( + path: .fromIdentityID({ identityId in + uniqueStringPath = "private/\(identityId)/\(key)" + return uniqueStringPath + "test1" + }), + data: data, + options: nil).value + } let firstListResult = try await Amplify.Storage.list(path: .fromString(uniqueStringPath)) @@ -198,10 +204,12 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase let uniqueStringPath = "public/\(path)" // Upload data - _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value - _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test2"), data: data, options: nil).value - _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath1/test"), data: data, options: nil).value - _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath2/test"), data: data, options: nil).value + await waitTasks(timeout: 15) { + _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value + _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test2"), data: data, options: nil).value + _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath1/test"), data: data, options: nil).value + _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath2/test"), data: data, options: nil).value + } let result = try await Amplify.Storage.list( path: .fromString("\(uniqueStringPath)/"), @@ -232,8 +240,10 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase let uniqueStringPath = "public/\(path)" // Upload data - _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-test"), data: data, options: nil).value - _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-subpath-test"), data: data, options: nil).value + await waitTasks(timeout: 10) { + _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-test"), data: data, options: nil).value + _ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-subpath-test"), data: data, options: nil).value + } let result = try await Amplify.Storage.list( path: .fromString("\(uniqueStringPath)-"), diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift index 4a3ffbc98f..b1b6ab2aed 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift @@ -63,8 +63,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { let key = UUID().uuidString let data = Data(key.utf8) - _ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value - _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value + _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + } // Only the remove operation results in an SDK request XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method } , [.delete]) @@ -80,8 +82,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { func testUploadEmptyData() async throws { let key = UUID().uuidString let data = Data("".utf8) - _ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value - _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value + _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + } XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) @@ -96,9 +100,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { let fileURL = URL(fileURLWithPath: filePath) FileManager.default.createFile(atPath: filePath, contents: Data(key.utf8), attributes: nil) - - _ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value - _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value + _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + } // Only the remove operation results in an SDK request XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method} , [.delete]) @@ -117,8 +122,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { let fileURL = URL(fileURLWithPath: filePath) FileManager.default.createFile(atPath: filePath, contents: Data("".utf8), attributes: nil) - _ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value - _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value + _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + } XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) @@ -130,12 +137,14 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { func testUploadLargeData() async throws { let key = "public/" + UUID().uuidString - let uploadKey = try await Amplify.Storage.uploadData(path: .fromString(key), - data: AWSS3StoragePluginTestBase.largeDataObject, - options: nil).value - XCTAssertEqual(uploadKey, key) + await waitTasks(timeout: 20) { + let uploadKey = try await Amplify.Storage.uploadData(path: .fromString(key), + data: AWSS3StoragePluginTestBase.largeDataObject, + options: nil).value + XCTAssertEqual(uploadKey, key) - try await Amplify.Storage.remove(path: .fromString(key)) + try await Amplify.Storage.remove(path: .fromString(key)) + } let userAgents = requestRecorder.urlRequests.compactMap { $0.allHTTPHeaderFields?["User-Agent"] } XCTAssertGreaterThan(userAgents.count, 1) @@ -157,8 +166,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { contents: AWSS3StoragePluginTestBase.largeDataObject, attributes: nil) - _ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value - _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + await waitTasks(timeout: 20) { + _ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value + _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) + } let userAgents = requestRecorder.urlRequests.compactMap { $0.allHTTPHeaderFields?["User-Agent"] } XCTAssertGreaterThan(userAgents.count, 1) diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadMetadataTestCase.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadMetadataTestCase.swift index 92d6ec8a7a..a27f760a93 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadMetadataTestCase.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadMetadataTestCase.swift @@ -27,11 +27,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase { // upload file let key = UUID().uuidString let fileURL = temporaryFile(named: key, data: data(mb: 1)) - _ = try await Amplify.Storage.uploadFile( - key: key, - local: fileURL, - options: options - ).value + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadFile( + key: key, + local: fileURL, + options: options + ).value + } // call `HeadObject` through SDK escape hatch let head = try await headObject(key: "public/\(key)") @@ -65,11 +67,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase { // upload file let key = UUID().uuidString let fileURL = temporaryFile(named: key, data: data(mb: 7)) - _ = try await Amplify.Storage.uploadFile( - key: key, - local: fileURL, - options: options - ).value + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadFile( + key: key, + local: fileURL, + options: options + ).value + } // call `HeadObject` through SDK escape hatch let head = try await headObject(key: "public/\(key)") @@ -102,11 +106,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase { // upload file let key = UUID().uuidString - _ = try await Amplify.Storage.uploadData( - key: key, - data: data(mb: 1), - options: options - ).value + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadData( + key: key, + data: self.data(mb: 1), + options: options + ).value + } // call `HeadObject` through SDK escape hatch let head = try await headObject(key: "public/\(key)") @@ -139,11 +145,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase { // upload file let key = UUID().uuidString - _ = try await Amplify.Storage.uploadData( - key: key, - data: data(mb: 7), - options: options - ).value + await waitTasks(timeout: 5) { + _ = try await Amplify.Storage.uploadData( + key: key, + data: self.data(mb: 7), + options: options + ).value + } // call `HeadObject` through SDK escape hatch let head = try await headObject(key: "public/\(key)") @@ -187,11 +195,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase { // upload file let key = UUID().uuidString - _ = try await Amplify.Storage.uploadData( - key: key, - data: data(mb: 1), - options: options - ).value + await waitTasks(timeout: 10) { + _ = try await Amplify.Storage.uploadData( + key: key, + data: self.data(mb: 1), + options: options + ).value + } // call `HeadObject` through SDK escape hatch let head = try await headObject(key: "public/\(key)")