From 0295c089c2f25043246e95ab0e9a48c9ac448236 Mon Sep 17 00:00:00 2001 From: Ian Saultz <52051793+atierian@users.noreply.github.com> Date: Thu, 12 Oct 2023 17:57:31 -0400 Subject: [PATCH] fix: unit test fulfillment --- ...phQLSubscriptionOperationCancelTests.swift | 28 +++++++-- ...pointAnalyticsPluginIntegrationTests.swift | 2 +- .../ClearCredentialsTests.swift | 20 ++++-- .../LoadCredentialsTests.swift | 20 ++++-- .../MigrateLegacyCredentialStoreTests.swift | 13 ++-- .../FetchAuthAWSCredentialsTests.swift | 28 +++++++-- .../RefreshUserPoolTokensTests.swift | 21 +++++-- .../InitializeFetchAuthSessionTests.swift | 5 +- .../InitiateAuthSRPTests.swift | 16 +++-- .../VerifyPasswordSRPTests.swift | 60 ++++++++++++++---- .../SignOut/RevokeTokenTests.swift | 15 ++++- .../SignOut/SignOutGloballyTests.swift | 16 +++-- .../VerifySignInChallengeTests.swift | 35 ++++++++--- .../AuthHubEventHandlerTests.swift | 35 ++++++++--- .../StateMachineListenerTests.swift | 25 ++++++-- .../StateMachineTests.swift | 17 ++++- .../SignedInAuthSessionTests.swift | 6 +- .../Core/AWSDataStorePluginTests.swift | 63 ++++++++++++------- .../Core/ListTests.swift | 3 +- .../Storage/CascadeDeleteOperationTests.swift | 27 ++++---- .../Storage/StorageEngineTestsBase.swift | 2 +- 21 files changed, 345 insertions(+), 112 deletions(-) diff --git a/AmplifyPlugins/API/Tests/AWSAPIPluginTests/Operation/AWSGraphQLSubscriptionOperationCancelTests.swift b/AmplifyPlugins/API/Tests/AWSAPIPluginTests/Operation/AWSGraphQLSubscriptionOperationCancelTests.swift index 3df0708918..10541326c5 100644 --- a/AmplifyPlugins/API/Tests/AWSAPIPluginTests/Operation/AWSGraphQLSubscriptionOperationCancelTests.swift +++ b/AmplifyPlugins/API/Tests/AWSAPIPluginTests/Operation/AWSGraphQLSubscriptionOperationCancelTests.swift @@ -110,8 +110,8 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase { valueListener: valueListener, completionListener: completionListener ) - await waitForExpectations(timeout: 5) - + await fulfillment(of: [receivedValueConnecting], timeout: 5) + let receivedCompletion = expectation(description: "Received completion") let receivedFailure = expectation(description: "Received failure") receivedFailure.isInverted = true @@ -145,7 +145,11 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase { operation.cancel() XCTAssert(operation.isCancelled) - await waitForExpectations(timeout: 5) + + await fulfillment( + of: [receivedCompletion, receivedFailure, receivedValueDisconnected], + timeout: 5 + ) } func testFailureOnConnection() async { @@ -184,7 +188,12 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase { valueListener: valueListener, completionListener: completionListener ) - await waitForExpectations(timeout: 0.3) + + await fulfillment( + of: [receivedCompletion, receivedFailure, receivedValue], + timeout: 0.3 + ) + XCTAssert(operation.isFinished) } @@ -221,7 +230,11 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase { valueListener: valueListener, completionListener: nil ) - await waitForExpectations(timeout: 5) + await fulfillment( + of: [receivedValue], + timeout: 5 + ) + let receivedFailure = expectation(description: "Received failure") receivedFailure.isInverted = true let receivedCompletion = expectation(description: "Received completion") @@ -237,6 +250,9 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase { operation.cancel() XCTAssert(operation.isCancelled) - await waitForExpectations(timeout: 5) + await fulfillment( + of: [receivedCompletion, receivedFailure], + timeout: 5 + ) } } diff --git a/AmplifyPlugins/Analytics/Tests/AnalyticsHostApp/AWSPinpointAnalyticsPluginIntegrationTests/AWSPinpointAnalyticsPluginIntegrationTests.swift b/AmplifyPlugins/Analytics/Tests/AnalyticsHostApp/AWSPinpointAnalyticsPluginIntegrationTests/AWSPinpointAnalyticsPluginIntegrationTests.swift index e15ba5dfaf..947f1a08b2 100644 --- a/AmplifyPlugins/Analytics/Tests/AnalyticsHostApp/AWSPinpointAnalyticsPluginIntegrationTests/AWSPinpointAnalyticsPluginIntegrationTests.swift +++ b/AmplifyPlugins/Analytics/Tests/AnalyticsHostApp/AWSPinpointAnalyticsPluginIntegrationTests/AWSPinpointAnalyticsPluginIntegrationTests.swift @@ -72,7 +72,7 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase { properties: properties) Amplify.Analytics.identifyUser(userId: userId, userProfile: userProfile) - await waitForExpectations(timeout: TestCommonConstants.networkTimeout) + await fulfillment(of: [identifyUserEvent], timeout: TestCommonConstants.networkTimeout) // Remove userId from the current endpoint let endpointClient = endpointClient() diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/ClearCredentialsTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/ClearCredentialsTests.swift index 09dc525141..8f3f2a6899 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/ClearCredentialsTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/ClearCredentialsTests.swift @@ -50,7 +50,10 @@ class ClearCredentialsTests: XCTestCase { await action.execute(withDispatcher: MockDispatcher { _ in }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } /// Test is responsible to check if configuration error is correctly caught by the action @@ -82,7 +85,10 @@ class ClearCredentialsTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } /// Test is responsible to check if the clear credentials handle a known error @@ -136,7 +142,10 @@ class ClearCredentialsTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } /// Test is responsible to check if the clear credentials handle an unknown error @@ -191,7 +200,10 @@ class ClearCredentialsTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/LoadCredentialsTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/LoadCredentialsTests.swift index c2a61e659d..2375daf8a6 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/LoadCredentialsTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/LoadCredentialsTests.swift @@ -67,7 +67,10 @@ class LoadCredentialsTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [loadCredentialHandlerInvoked], + timeout: 0.1 + ) } /// Test is responsible to check if configuration error is correctly caught by the action @@ -99,7 +102,10 @@ class LoadCredentialsTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } /// Test is responsible to check if the load credentials handle a known error @@ -153,7 +159,10 @@ class LoadCredentialsTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } /// Test is responsible to check if the load credentials handle an unknown error @@ -210,7 +219,10 @@ class LoadCredentialsTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/MigrateLegacyCredentialStoreTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/MigrateLegacyCredentialStoreTests.swift index d4a0248e34..06ebd109c9 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/MigrateLegacyCredentialStoreTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/CredentialStore/MigrateLegacyCredentialStoreTests.swift @@ -72,7 +72,11 @@ class MigrateLegacyCredentialStoreTests: XCTestCase { let action = MigrateLegacyCredentialStore() await action.execute(withDispatcher: MockDispatcher { _ in }, environment: environment) - await waitForExpectations(timeout: 0.1) + + await fulfillment( + of: [saveCredentialHandlerInvoked], + timeout: 0.1 + ) } /// Test is responsible for making sure that the legacy credential store clearing up is getting called for user pool and identity pool @@ -115,8 +119,9 @@ class MigrateLegacyCredentialStoreTests: XCTestCase { let action = MigrateLegacyCredentialStore() await action.execute(withDispatcher: MockDispatcher { _ in }, environment: environment) - await waitForExpectations(timeout: 0.1) - + await fulfillment( + of: [migrationCompletionInvoked], + timeout: 0.1 + ) } - } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchAWSCredentials/FetchAuthAWSCredentialsTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchAWSCredentials/FetchAuthAWSCredentialsTests.swift index 5ee9586a47..fa4e75a9ce 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchAWSCredentials/FetchAuthAWSCredentialsTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchAWSCredentials/FetchAuthAWSCredentialsTests.swift @@ -30,7 +30,11 @@ class FetchAuthAWSCredentialsTests: XCTestCase { expectation.fulfill() } }, environment: MockInvalidEnvironment()) - await waitForExpectations(timeout: 0.1) + + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } func testInvalidIdentitySuccessfullResponse() async { @@ -60,7 +64,10 @@ class FetchAuthAWSCredentialsTests: XCTestCase { } }, environment: authEnvironment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } func testInvalidAWSCredentialSuccessfulResponse() async { @@ -93,7 +100,10 @@ class FetchAuthAWSCredentialsTests: XCTestCase { environment: authEnvironment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } func testValidSuccessfulResponse() async { @@ -134,7 +144,11 @@ class FetchAuthAWSCredentialsTests: XCTestCase { }, environment: authEnvironment ) - await waitForExpectations(timeout: 0.1) + + await fulfillment( + of: [credentialValidExpectation], + timeout: 0.1 + ) } func testFailureResponse() async { @@ -166,7 +180,11 @@ class FetchAuthAWSCredentialsTests: XCTestCase { }, environment: authEnvironment ) - await waitForExpectations(timeout: 0.1) + + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift index a98e7124f3..ad029fbf67 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift @@ -34,7 +34,10 @@ class RefreshUserPoolTokensTests: XCTestCase { }, environment: MockInvalidEnvironment() ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } func testInvalidSuccessfulResponse() async { @@ -63,7 +66,10 @@ class RefreshUserPoolTokensTests: XCTestCase { userPoolFactory: identityProviderFactory) ) - await waitForExpectations(timeout: 1) + await fulfillment( + of: [expectation], + timeout: 1 + ) } func testValidSuccessfulResponse() async { @@ -93,7 +99,11 @@ class RefreshUserPoolTokensTests: XCTestCase { }, environment: Defaults.makeDefaultAuthEnvironment( userPoolFactory: identityProviderFactory) ) - await waitForExpectations(timeout: 0.1) + + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } func testFailureResponse() async { @@ -128,7 +138,10 @@ class RefreshUserPoolTokensTests: XCTestCase { } }, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/InitializeFetchAuthSessionTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/InitializeFetchAuthSessionTests.swift index 9c60fad781..4976285b0e 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/InitializeFetchAuthSessionTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/InitializeFetchAuthSessionTests.swift @@ -32,7 +32,10 @@ class InitializeFetchAuthSessionTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [expectation], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/InitiateAuthSRPTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/InitiateAuthSRPTests.swift index 2ad9ef7ee9..9ce542f0a2 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/InitiateAuthSRPTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/InitiateAuthSRPTests.swift @@ -32,7 +32,10 @@ class InitiateAuthSRPTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [initiateAuthInvoked], + timeout: 0.1 + ) } func testFailedInitiateAuthPropagatesError() async { @@ -70,7 +73,10 @@ class InitiateAuthSRPTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [errorEventSent], + timeout: 0.1 + ) } func testSuccessfulInitiateAuthPropagatesSuccess() async { @@ -106,7 +112,9 @@ class InitiateAuthSRPTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [successEventSent], + timeout: 0.1 + ) } - } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/VerifyPasswordSRPTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/VerifyPasswordSRPTests.swift index 74efd601fb..2a61b88576 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/VerifyPasswordSRPTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/InitiateAuthSRP/VerifyPasswordSRPTests.swift @@ -48,7 +48,10 @@ class VerifyPasswordSRPTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [verifyPasswordInvoked], + timeout: 0.1 + ) } /// Test empty response is returned by Cognito proper error is thrown @@ -96,7 +99,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test invalid challenge response from initiate auth @@ -144,7 +150,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test challenge response with no salt from initiate auth @@ -192,7 +201,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test challenge response with no secretblock from initiate auth @@ -240,7 +252,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test challenge response with no SRPB from initiate auth @@ -288,7 +303,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test an exception from the SRP calculation @@ -336,7 +354,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test successful response from the VerifyPasswordSRP @@ -379,7 +400,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test successful response from the VerifyPasswordSRP @@ -432,7 +456,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test verify password retry on device not found @@ -478,7 +505,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test successful response from the VerifyPasswordSRP for confirmDevice @@ -521,7 +551,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierCompletion], + timeout: 0.1 + ) } /// Test successful response from the VerifyPasswordSRP for verifyDevice @@ -564,7 +597,10 @@ class VerifyPasswordSRPTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierCompletion], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/RevokeTokenTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/RevokeTokenTests.swift index eeab3c66de..31bf393a06 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/RevokeTokenTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/RevokeTokenTests.swift @@ -38,7 +38,10 @@ class RevokeTokenTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [revokeTokenInvoked], + timeout: 0.1 + ) } func testFailedRevokeTokenTriggersClearCredentialStore() async { @@ -79,7 +82,10 @@ class RevokeTokenTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [clearCredentialStoreEventSent], + timeout: 0.1 + ) } func testSuccessfulRevokeTokenTriggersClearCredentialStore() async { @@ -120,7 +126,10 @@ class RevokeTokenTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [clearCredentialStoreEventSent], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/SignOutGloballyTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/SignOutGloballyTests.swift index d0af7dd4e5..03d00fae34 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/SignOutGloballyTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/SignOut/SignOutGloballyTests.swift @@ -36,7 +36,10 @@ class SignOutGloballyTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [globalSignOutInvoked], + timeout: 0.1 + ) } func testFailedGlobalSignOutTriggersBuildRevokeError() async { @@ -75,7 +78,10 @@ class SignOutGloballyTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [revokeTokenEventSent], + timeout: 0.1 + ) } func testSuccessfulGlobalSignOutTriggersRevokeToken() async { @@ -114,7 +120,9 @@ class SignOutGloballyTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [revokeTokenEventSent], + timeout: 0.1 + ) } - } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/VerifySignInChallenge/VerifySignInChallengeTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/VerifySignInChallenge/VerifySignInChallengeTests.swift index b123bdc820..f421ac3f57 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/VerifySignInChallenge/VerifySignInChallengeTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/VerifySignInChallenge/VerifySignInChallengeTests.swift @@ -56,7 +56,10 @@ class VerifySignInChallengeTests: XCTestCase { environment: environment ) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [verifyPasswordInvoked], + timeout: 0.1 + ) } /// Test empty response is returned by Cognito proper error is thrown @@ -103,7 +106,10 @@ class VerifySignInChallengeTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test successful response from the VerifySignInChallenge @@ -144,7 +150,10 @@ class VerifySignInChallengeTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [verifyChallengeComplete], + timeout: 0.1 + ) } /// Test successful response from the VerifySignInChallenge @@ -196,7 +205,10 @@ class VerifySignInChallengeTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test verify password retry on device not found @@ -240,7 +252,10 @@ class VerifySignInChallengeTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [passwordVerifierError], + timeout: 0.1 + ) } /// Test successful response from the VerifySignInChallenge for confirmDevice @@ -281,7 +296,10 @@ class VerifySignInChallengeTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [verifyChallengeComplete], + timeout: 0.1 + ) } /// Test successful response from the VerifySignInChallenge for verify device @@ -322,6 +340,9 @@ class VerifySignInChallengeTests: XCTestCase { } await action.execute(withDispatcher: dispatcher, environment: environment) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [verifyChallengeComplete], + timeout: 0.1 + ) } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift index 8fe8f7bbae..6618988f58 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift @@ -48,7 +48,10 @@ class AuthHubEventHandlerTests: XCTestCase { XCTFail("Received failure with error \(error)") } - await waitForExpectations(timeout: networkTimeout) + await fulfillment( + of: [hubEventExpectation], + timeout: networkTimeout + ) } /// Test whether HubEvent emits a signOut event for mocked signOut operation @@ -74,7 +77,10 @@ class AuthHubEventHandlerTests: XCTestCase { } _ = await plugin.signOut(options: nil) - await waitForExpectations(timeout: networkTimeout) + await fulfillment( + of: [hubEventExpectation], + timeout: networkTimeout + ) } /// Test whether HubEvent emits a confirmSignedIn event for mocked signIn operation @@ -105,7 +111,10 @@ class AuthHubEventHandlerTests: XCTestCase { XCTFail("Received failure with error \(error)") } - await waitForExpectations(timeout: networkTimeout) + await fulfillment( + of: [hubEventExpectation], + timeout: networkTimeout + ) } /// Test whether HubEvent emits a deletedUser event for mocked delete user operation @@ -136,7 +145,10 @@ class AuthHubEventHandlerTests: XCTestCase { XCTFail("Received failure with error \(error)") } - await waitForExpectations(timeout: networkTimeout) + await fulfillment( + of: [hubEventExpectation], + timeout: networkTimeout + ) } /// Test whether HubEvent emits a sessionExpired event for mocked fetchSession operation with expired tokens @@ -161,7 +173,10 @@ class AuthHubEventHandlerTests: XCTestCase { } } _ = try await plugin.fetchAuthSession(options: AuthFetchSessionRequest.Options()) - await waitForExpectations(timeout: networkTimeout) + await fulfillment( + of: [hubEventExpectation], + timeout: networkTimeout + ) } #if os(iOS) || os(macOS) @@ -254,7 +269,10 @@ class AuthHubEventHandlerTests: XCTestCase { } _ = try await plugin.federateToIdentityPool(withProviderToken: "someToken", for: .facebook) - await waitForExpectations(timeout: networkTimeout) + await fulfillment( + of: [hubEventExpectation], + timeout: networkTimeout + ) } /// Test whether HubEvent emits a federationToIdentityPoolCleared event for mocked federated operation @@ -282,7 +300,10 @@ class AuthHubEventHandlerTests: XCTestCase { _ = try await plugin.federateToIdentityPool(withProviderToken: "something", for: .facebook) try await plugin.clearFederationToIdentityPool() - await waitForExpectations(timeout: networkTimeout) + await fulfillment( + of: [hubEventExpectation], + timeout: networkTimeout + ) } private func configurePluginForSignInEvent() { diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineListenerTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineListenerTests.swift index 62cf4328ec..cdb8ccdc6b 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineListenerTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineListenerTests.swift @@ -41,7 +41,10 @@ class StateMachineListenerTests: XCTestCase { } let event = Counter.Event(id: "test", eventType: .increment) await stateMachine.send(event) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [notified], + timeout: 0.1 + ) } func testDoesNotNotifyOnNoStateChange() async { @@ -58,7 +61,10 @@ class StateMachineListenerTests: XCTestCase { let event = Counter.Event(id: "test", eventType: .adjustBy(0)) await stateMachine.send(event) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [notified], + timeout: 0.1 + ) } func testDoesNotNotifyAfterUnsubscribe() async { @@ -77,7 +83,10 @@ class StateMachineListenerTests: XCTestCase { seq.cancel() let event = Counter.Event(id: "test", eventType: .increment) await stateMachine.send(event) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [notified], + timeout: 0.1 + ) } func testOrderOfSubsription() async throws { @@ -109,7 +118,10 @@ class StateMachineListenerTests: XCTestCase { try await Task.sleep(nanoseconds: 1_000_000) await self.stateMachine.send(Counter.Event(id: "set3", eventType: .set(12))) } - await waitForExpectations(timeout: 2) + await fulfillment( + of: [notified], + timeout: 2 + ) seq.cancel() } } @@ -143,7 +155,10 @@ class StateMachineListenerTests: XCTestCase { } } - await waitForExpectations(timeout: 1) + await fulfillment( + of: [notified], + timeout: 1 + ) task2.cancel() } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineTests.swift index 59902bb014..c0d3dbca65 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/hierarchical-state-machine-swiftTests/StateMachineTests.swift @@ -49,7 +49,11 @@ class StateMachineTests: XCTestCase { taskCompletion.fulfill() } } - await waitForExpectations(timeout: 1) + + await fulfillment( + of: [taskCompletion], + timeout: 0.1 + ) let state = await testMachine.currentState XCTAssertEqual(state.value, 0) } @@ -106,7 +110,10 @@ class StateMachineTests: XCTestCase { ) await testMachine.send(event) - await waitForExpectations(timeout: 0.1) + await fulfillment( + of: [action1WasExecuted, action2WasExecuted], + timeout: 0.1 + ) } /// Given: @@ -148,7 +155,11 @@ class StateMachineTests: XCTestCase { ) await testMachine.send(event) - await waitForExpectations(timeout: 0.1) + + await fulfillment( + of: [action1WasExecuted, action2WasExecuted], + timeout: 0.1 + ) XCTAssertEqual(executionCount.get(), 2) } diff --git a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/SessionTests/SignedInAuthSessionTests.swift b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/SessionTests/SignedInAuthSessionTests.swift index 054796d33e..159f222430 100644 --- a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/SessionTests/SignedInAuthSessionTests.swift +++ b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/SessionTests/SignedInAuthSessionTests.swift @@ -233,7 +233,11 @@ class SignedInAuthSessionTests: AWSAuthBaseTest { fetchSessionExptectation.fulfill() } } - await waitForExpectations(timeout: networkTimeout) + + await fulfillment( + of: [identityIDExpectation, fetchSessionExptectation], + timeout: networkTimeout + ) } /// Test if successful session is retrieved before and after a user sign in diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/AWSDataStorePluginTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/AWSDataStorePluginTests.swift index e1f5dd051f..dbcf4a03f3 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/AWSDataStorePluginTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/AWSDataStorePluginTests.swift @@ -82,13 +82,17 @@ class AWSDataStorePluginTests: XCTestCase { let queryCompleted = expectation(description: "query completed") Task { _ = try await plugin.query(ExampleWithEveryType.self) - await queryCompleted.fulfill() + queryCompleted.fulfill() } await fulfillment(of: [queryCompleted], timeout: 1.0) } catch { XCTFail("DataStore configuration should not fail with nil configuration. \(error)") } - await waitForExpectations(timeout: 1.0) + + await fulfillment( + of: [startExpectation], + timeout: 1 + ) } func testStorageEngineStartsOnPluginStopStart() throws { @@ -212,7 +216,7 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) startCompleted.fulfill() }) - await fulfillment(of: [startCompleted], timeout: 1.0) + wait(for: [startCompleted], timeout: 1.0) let stopCompleted = expectation(description: "stop completed") plugin.stop(completion: { _ in @@ -220,7 +224,7 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) stopCompleted.fulfill() }) - await fulfillment(of: [stopCompleted], timeout: 1.0) + wait(for: [stopCompleted], timeout: 1.0) storageEngine.responders[.startSync] = StartSyncResponder { _ in startExpectationOnSecondStart.fulfill() @@ -230,8 +234,12 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.storageEngine) XCTAssertNotNil(plugin.dataStorePublisher) }) - await fulfillment(of: [startExpectation, stopExpectation, startExpectationOnSecondStart], timeout: 1, enforceOrder: true) - await fulfillment(of: [finishNotReceived], timeout: 1) + wait( + for: [startExpectation, stopExpectation, startExpectationOnSecondStart], + timeout: 1, + enforceOrder: true + ) + wait(for: [finishNotReceived], timeout: 1) sink.cancel() } catch { XCTFail("DataStore configuration should not fail with nil configuration. \(error)") @@ -283,7 +291,7 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) startCompleted.fulfill() }) - await fulfillment(of: [startCompleted], timeout: 1.0) + wait(for: [startCompleted], timeout: 1.0) let clearCompleted = expectation(description: "clear completed") plugin.clear(completion: { _ in @@ -291,7 +299,7 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) clearCompleted.fulfill() }) - await fulfillment(of: [clearCompleted], timeout: 1.0) + wait(for: [clearCompleted], timeout: 1.0) storageEngine.responders[.startSync] = StartSyncResponder {_ in startExpectationOnSecondStart.fulfill() @@ -301,8 +309,13 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.storageEngine) XCTAssertNotNil(plugin.dataStorePublisher) }) - await fulfillment(of: [startExpectation, clearExpectation, startExpectationOnSecondStart], timeout: 1, enforceOrder: true) - await fulfillment(of: [finishNotReceived], timeout: 1) + + wait( + for: [startExpectation, clearExpectation, startExpectationOnSecondStart], + timeout: 1, + enforceOrder: true + ) + wait(for: [finishNotReceived], timeout: 1) sink.cancel() } catch { XCTFail("DataStore configuration should not fail with nil configuration. \(error)") @@ -356,7 +369,7 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) queryCompleted.fulfill() }) - await fulfillment(of: [queryCompleted], timeout: 1.0) + wait(for: [queryCompleted], timeout: 1.0) let clearCompleted = expectation(description: "clear completed") plugin.clear(completion: { _ in @@ -364,7 +377,7 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) clearCompleted.fulfill() }) - await fulfillment(of: [clearCompleted], timeout: 1.0) + wait(for: [clearCompleted], timeout: 1.0) storageEngine.responders[.query] = QueryResponder {_ in count = self.expect(startExpectationOnQuery, count, 3) return .success([]) @@ -448,15 +461,15 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) startCompleted.fulfill() }) - await fulfillment(of: [startCompleted], timeout: 1.0) - + wait(for: [startCompleted], timeout: 1.0) + let clearCompleted = expectation(description: "clear completed") plugin.clear(completion: { _ in XCTAssertNil(plugin.storageEngine) XCTAssertNotNil(plugin.dataStorePublisher) clearCompleted.fulfill() }) - await fulfillment(of: [clearCompleted], timeout: 1.0) + wait(for: [clearCompleted], timeout: 1.0) let mockModel = MockSynced(id: "12345") try plugin.dataStorePublisher?.send(input: MutationEvent(model: mockModel, @@ -527,23 +540,27 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) startCompleted.fulfill() }) - await fulfillment(of: [startCompleted], timeout: 1.0) - + wait(for: [startCompleted], timeout: 1.0) + let stopCompleted = expectation(description: "stop completed") plugin.stop(completion: { _ in XCTAssertNotNil(plugin.storageEngine) XCTAssertNotNil(plugin.dataStorePublisher) stopCompleted.fulfill() }) - await fulfillment(of: [stopCompleted], timeout: 1.0) + wait(for: [stopCompleted], timeout: 1.0) - await fulfillment(of: [startExpectation, stopExpectation], timeout: 1, enforceOrder: true) + wait( + for: [startExpectation, stopExpectation], + timeout: 1, + enforceOrder: true + ) let mockModel = MockSynced(id: "12345") try plugin.dataStorePublisher?.send(input: MutationEvent(model: mockModel, modelSchema: mockModel.schema, mutationType: .create)) - await fulfillment(of: [publisherReceivedValue, finishNotReceived], timeout: 1) + wait(for: [publisherReceivedValue, finishNotReceived], timeout: 1) sink.cancel() } catch { XCTFail("DataStore configuration should not fail with nil configuration. \(error)") @@ -602,11 +619,11 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) startCompleted.fulfill() }) - await fulfillment(of: [startCompleted], timeout: 1.0) + wait(for: [startCompleted], timeout: 1.0) storageEngine.mockSyncEnginePublisher.send(completion: .finished) - await fulfillment(of: [stopExpectation], timeout: 1) + wait(for: [stopExpectation], timeout: 1) } func testStopStorageEngineOnTerminalFailureEvent() { @@ -632,7 +649,7 @@ class AWSDataStorePluginTests: XCTestCase { XCTAssertNotNil(plugin.dataStorePublisher) startCompleted.fulfill() }) - await fulfillment(of: [startCompleted], timeout: 1.0) + wait(for: [startCompleted], timeout: 1.0) storageEngine.mockSyncEnginePublisher.send(completion: .failure(.internalOperation("", "", nil))) diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift index e0a84f58d5..6dcd83dbd7 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift @@ -49,7 +49,8 @@ class ListTests: BaseDataStoreTests { XCTFail("\(error)") } - await waitForExpectations(timeout: 1) + + await fulfillment(of: [expect], timeout: 1) } // MARK: - Helpers diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/CascadeDeleteOperationTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/CascadeDeleteOperationTests.swift index bebdeed679..241c08eefb 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/CascadeDeleteOperationTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/CascadeDeleteOperationTests.swift @@ -87,7 +87,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await waitForExpectations(timeout: 1) + await fulfillment(of: [completed], timeout: 1) guard case .success(let queriedRestaurants) = await queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -132,7 +132,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await fulfillment(of: [completed], timeout: 1) + wait(for: [completed], timeout: 1) guard case .success(let queriedModel) = queryModelSynchronous(modelType: ModelCompositePk.self, predicate: predicate) else { XCTFail("Failed to query") @@ -174,7 +174,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await fulfillment(of: [completed], timeout: 1) + wait(for: [completed], timeout: 1) guard case .success(let queriedRestaurants) = queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -219,7 +219,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await fulfillment(of: [completed], timeout: 1) + wait(for: [completed], timeout: 1) guard case .success(let queriedRestaurants) = queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -261,7 +261,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await fulfillment(of: [completed], timeout: 1) + wait(for: [completed], timeout: 1) guard case .success(let queriedRestaurants) = queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -301,7 +301,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await fulfillment(of: [completed], timeout: 1) + wait(for: [completed], timeout: 1) guard case .success(let queriedRestaurants) = queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -361,7 +361,8 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await waitForExpectations(timeout: 1) + + await fulfillment(of: [receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) guard case .success(let queriedRestaurants) = await queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -422,7 +423,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await waitForExpectations(timeout: 1) + await fulfillment(of: [receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) guard case .success(let queriedModels) = await queryModelSynchronous(modelType: ModelCompositePk.self, predicate: predicate) else { XCTFail("Failed to query") @@ -483,7 +484,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await fulfillment(of: [completed, receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) + wait(for: [completed, receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) guard case .success(let queriedRestaurants) = queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -543,7 +544,7 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } } operation.start() - await fulfillment(of: [completed, receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) + wait(for: [completed, receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) guard case .success(let queriedRestaurants) = queryModelSynchronous(modelType: Restaurant.self, predicate: predicate) else { XCTFail("Failed to query") @@ -729,7 +730,8 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } operation.syncIfNeededAndFinish(result) - await waitForExpectations(timeout: 1) + await fulfillment(of: [receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) + XCTAssertEqual(submittedEvents.count, 2) // The delete mutations should be synced in reverse order (children to parent) XCTAssertEqual(submittedEvents[0].modelName, CommentWithCompositeKey.modelName) @@ -797,7 +799,8 @@ class CascadeDeleteOperationTests: StorageEngineTestsBase { } operation.syncIfNeededAndFinish(result) - await waitForExpectations(timeout: 1) + await fulfillment(of: [receivedMutationEvent, expectedFailures, expectedSuccess], timeout: 1) + XCTAssertEqual(submittedEvents.count, 3) // The delete mutations should be synced in reverse order (children to parent) XCTAssertEqual(submittedEvents[0].modelName, Dish.modelName) diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/StorageEngineTestsBase.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/StorageEngineTestsBase.swift index a713167bfe..97e0bde6da 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/StorageEngineTestsBase.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Storage/StorageEngineTestsBase.swift @@ -32,7 +32,7 @@ class StorageEngineTestsBase: XCTestCase { result = sResult saveFinished.fulfill() } - await fulfillment(of: [saveFinished], timeout: defaultTimeout) + wait(for: [saveFinished], timeout: defaultTimeout) guard let saveResult = result else { return .failure(causedBy: "Save operation timed out") }