From bdc9b4a1f2b1e426e159d66860085f062c47a568 Mon Sep 17 00:00:00 2001 From: Abhash Kumar Singh Date: Thu, 19 Oct 2023 07:47:36 -0700 Subject: [PATCH 1/2] feat(datastore): Add `isLoaded` public property in List+Model (#3296) --- .../DataStore/Model/Lazy/List+Model.swift | 10 ++++++++++ .../AWSDataStorePluginTests/Core/ListTests.swift | 16 +++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift b/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift index 09c3b8a3cd..aee10e9e53 100644 --- a/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift +++ b/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift @@ -26,6 +26,15 @@ public class List: Collection, Codable, ExpressibleByArrayLite /// The current state of lazily loaded list var loadedState: LoadedState + + /// Boolean property to check if list is loaded + public var isLoaded: Bool { + if case .loaded = loadedState { + return true + } + + return false + } /// The provider for fulfilling list behaviors let listProvider: AnyModelListProvider @@ -61,6 +70,7 @@ public class List: Collection, Codable, ExpressibleByArrayLite } } + // MARK: - Initializers public init(listProvider: AnyModelListProvider) { diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift index 31bdb24e5c..b2dcb3b347 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift @@ -8,9 +8,9 @@ import Combine import XCTest -@testable import Amplify -@testable import AmplifyTestCommon -@testable import AWSDataStorePlugin +import Amplify +import AmplifyTestCommon +import AWSDataStorePlugin class ListTests: BaseDataStoreTests { @@ -25,15 +25,9 @@ class ListTests: BaseDataStoreTests { let postId = preparePostDataForTest() func checkComments(_ comments: List) async throws { - guard case .notLoaded = comments.loadedState else { - XCTFail("Should not be loaded") - return - } + XCTAssertFalse(comments.isLoaded) try await comments.fetch() - guard case .loaded = comments.loadedState else { - XCTFail("Should be loaded") - return - } + XCTAssertTrue(comments.isLoaded) XCTAssertEqual(comments.count, 2) expect.fulfill() } From 99f66d390af92a02c92e6a2ce1befb66b13df1c8 Mon Sep 17 00:00:00 2001 From: Ian Saultz <52051793+atierian@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:19:29 -0400 Subject: [PATCH 2/2] test: fix failing datastore integration tests (#3317) --- .../integ_test_datastore_auth_cognito.yml | 3 +++ .../workflows/integ_test_datastore_auth_iam.yml | 3 +++ .github/workflows/integ_test_datastore_base.yml | 3 +++ .github/workflows/integ_test_datastore_cpk.yml | 3 +++ .../workflows/integ_test_datastore_lazy_load.yml | 3 +++ .../workflows/integ_test_datastore_multi_auth.yml | 3 +++ .github/workflows/integ_test_datastore_v2.yml | 3 +++ ...aStoreCategoryPluginAuthIntegrationTests.swift | 2 +- .../DataStoreObserveQueryTests.swift | 15 +++++++++++---- 9 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/integ_test_datastore_auth_cognito.yml b/.github/workflows/integ_test_datastore_auth_cognito.yml index 2bcabe1f1e..7ef3ab196b 100644 --- a/.github/workflows/integ_test_datastore_auth_cognito.yml +++ b/.github/workflows/integ_test_datastore_auth_cognito.yml @@ -35,6 +35,7 @@ jobs: scheme: AWSDataStorePluginAuthCognitoTests destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4' xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-auth-cognito-test-tvOS: timeout-minutes: 60 @@ -64,6 +65,7 @@ jobs: destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest sdk: appletvsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-auth-cognito-test-watchOS: timeout-minutes: 60 @@ -93,3 +95,4 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' diff --git a/.github/workflows/integ_test_datastore_auth_iam.yml b/.github/workflows/integ_test_datastore_auth_iam.yml index 25e7600163..44e7bd0f65 100644 --- a/.github/workflows/integ_test_datastore_auth_iam.yml +++ b/.github/workflows/integ_test_datastore_auth_iam.yml @@ -35,6 +35,7 @@ jobs: scheme: AWSDataStorePluginAuthIAMTests destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4' xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-auth-iam-test-tvOS: timeout-minutes: 60 @@ -64,6 +65,7 @@ jobs: destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest sdk: appletvsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-auth-iam-test-watchOS: timeout-minutes: 60 @@ -93,3 +95,4 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' diff --git a/.github/workflows/integ_test_datastore_base.yml b/.github/workflows/integ_test_datastore_base.yml index 7b42357b6f..504e887004 100644 --- a/.github/workflows/integ_test_datastore_base.yml +++ b/.github/workflows/integ_test_datastore_base.yml @@ -35,6 +35,7 @@ jobs: scheme: AWSDataStorePluginIntegrationTests destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4' xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-test-base-tvOS: timeout-minutes: 60 @@ -64,6 +65,7 @@ jobs: destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest sdk: appletvsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-test-base-watchOS: timeout-minutes: 60 @@ -93,3 +95,4 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' diff --git a/.github/workflows/integ_test_datastore_cpk.yml b/.github/workflows/integ_test_datastore_cpk.yml index 9032d7dd86..bcd5f18f5f 100644 --- a/.github/workflows/integ_test_datastore_cpk.yml +++ b/.github/workflows/integ_test_datastore_cpk.yml @@ -35,6 +35,7 @@ jobs: scheme: AWSDataStorePluginCPKTests destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4' xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-cpk-test-tvOS: timeout-minutes: 60 @@ -64,6 +65,7 @@ jobs: destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest sdk: appletvsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-cpk-test-watchOS: timeout-minutes: 60 @@ -93,3 +95,4 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' \ No newline at end of file diff --git a/.github/workflows/integ_test_datastore_lazy_load.yml b/.github/workflows/integ_test_datastore_lazy_load.yml index cc1481b00b..2fa088b9a9 100644 --- a/.github/workflows/integ_test_datastore_lazy_load.yml +++ b/.github/workflows/integ_test_datastore_lazy_load.yml @@ -35,6 +35,7 @@ jobs: scheme: AWSDataStorePluginLazyLoadTests destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4' xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-lazy-load-test-tvOS: timeout-minutes: 60 @@ -64,6 +65,7 @@ jobs: destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest sdk: appletvsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-lazy-load-test-watchOS: timeout-minutes: 60 @@ -93,3 +95,4 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' diff --git a/.github/workflows/integ_test_datastore_multi_auth.yml b/.github/workflows/integ_test_datastore_multi_auth.yml index 232ba5a5a6..eb096a403d 100644 --- a/.github/workflows/integ_test_datastore_multi_auth.yml +++ b/.github/workflows/integ_test_datastore_multi_auth.yml @@ -35,6 +35,7 @@ jobs: scheme: AWSDataStorePluginMultiAuthTests destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4' xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-multi-auth-test-tvOS: timeout-minutes: 60 @@ -64,6 +65,7 @@ jobs: destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest sdk: appletvsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-multi-auth-test-watchOS: timeout-minutes: 60 @@ -93,3 +95,4 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' diff --git a/.github/workflows/integ_test_datastore_v2.yml b/.github/workflows/integ_test_datastore_v2.yml index e24c75f9d4..a9e682f27e 100644 --- a/.github/workflows/integ_test_datastore_v2.yml +++ b/.github/workflows/integ_test_datastore_v2.yml @@ -35,6 +35,7 @@ jobs: scheme: AWSDataStorePluginV2Tests destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4' xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-v2-test-tvOS: timeout-minutes: 60 @@ -64,6 +65,7 @@ jobs: destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest sdk: appletvsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' datastore-integration-v2-test-watchOS: timeout-minutes: 60 @@ -93,3 +95,4 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + other_flags: '-test-iterations 3 -retry-tests-on-failure' diff --git a/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginAuthCognitoTests/AWSDataStoreCategoryPluginAuthIntegrationTests.swift b/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginAuthCognitoTests/AWSDataStoreCategoryPluginAuthIntegrationTests.swift index 0a2efbf5db..eefc8b2dd0 100644 --- a/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginAuthCognitoTests/AWSDataStoreCategoryPluginAuthIntegrationTests.swift +++ b/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginAuthCognitoTests/AWSDataStoreCategoryPluginAuthIntegrationTests.swift @@ -60,7 +60,7 @@ class AWSDataStoreCategoryPluginAuthIntegrationTests: AWSDataStoreAuthBaseTest { try await signIn(user: user1) - await fulfillment(of: [syncReceivedInvoked], timeout: TestCommonConstants.networkTimeout) + await fulfillment(of: [syncReceivedInvoked], timeout: 60) Amplify.Hub.removeListener(syncReceivedListener) guard let remoteTodo = remoteTodoOptional else { XCTFail("Should have received a SyncReceived event with the remote note reconciled to local store") diff --git a/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginIntegrationTests/DataStoreObserveQueryTests.swift b/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginIntegrationTests/DataStoreObserveQueryTests.swift index 372e550a8f..2ac54a0f71 100644 --- a/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginIntegrationTests/DataStoreObserveQueryTests.swift +++ b/AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginIntegrationTests/DataStoreObserveQueryTests.swift @@ -97,9 +97,16 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase { } }.store(in: &cancellables) let receivedPost = expectation(description: "received Post") - try await savePostAndWaitForSync(Post(title: "title", content: "content", createdAt: .now()), - postSyncedExpctation: receivedPost) - await fulfillment(of: [snapshotWithIsSynced, receivedPost], timeout: 100) + receivedPost.assertForOverFulfill = false + try await savePostAndWaitForSync( + Post( + title: "title", + content: "content", + createdAt: .now() + ), + postSyncedExpctation: receivedPost + ) + await fulfillment(of: [snapshotWithIsSynced], timeout: 100) XCTAssertTrue(snapshots.count >= 2) XCTAssertFalse(snapshots[0].isSynced) @@ -296,7 +303,7 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase { let receivedPost = expectation(description: "received Post") try await savePostAndWaitForSync(Post(title: "title", content: "content", createdAt: .now()), postSyncedExpctation: receivedPost) - await fulfillment(of: [snapshotWithIsSynced, receivedPost], timeout: 30) + await fulfillment(of: [snapshotWithIsSynced], timeout: 30) XCTAssertTrue(snapshots.count >= 2) XCTAssertFalse(snapshots[0].isSynced) XCTAssertTrue(snapshots.last!.isSynced)