Skip to content

Commit

Permalink
test: datastore remove waitForListener awaits
Browse files Browse the repository at this point in the history
  • Loading branch information
atierian committed Oct 18, 2023
1 parent 974cc29 commit 6c42abf
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,10 @@ class AWSDataStoreCategoryPluginAuthIntegrationTests: AWSDataStoreAuthBaseTest {
syncReceivedInvoked.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: syncReceivedListener, timeout: 5.0) else {
XCTFail("syncReceivedListener registered for hub")
return
}

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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ class DataStoreConnectionScenario1Tests: SyncEngineIntegrationTestBase {
syncedTeamReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(team)
await fulfillment(of: [syncedTeamReceived], timeout: networkTimeout)
Expand All @@ -81,10 +78,7 @@ class DataStoreConnectionScenario1Tests: SyncEngineIntegrationTestBase {
syncProjectReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.save(project)
await fulfillment(of: [syncProjectReceived], timeout: networkTimeout)

Expand Down Expand Up @@ -122,10 +116,7 @@ class DataStoreConnectionScenario1Tests: SyncEngineIntegrationTestBase {
syncUpdatedProjectReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

project.team = anotherTeam
_ = try await Amplify.DataStore.save(project)
await fulfillment(of: [syncUpdatedProjectReceived], timeout: networkTimeout)
Expand Down Expand Up @@ -168,10 +159,7 @@ class DataStoreConnectionScenario1Tests: SyncEngineIntegrationTestBase {
}
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(team)
_ = try await Amplify.DataStore.save(project)
Expand All @@ -198,10 +186,7 @@ class DataStoreConnectionScenario1Tests: SyncEngineIntegrationTestBase {
}
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.delete(project)

// TODO: Delete Team should not be necessary, cascade delete should delete the team when deleting the project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ class DataStoreConnectionScenario2Tests: SyncEngineIntegrationTestBase {
syncProjectReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(team)
await fulfillment(of: [syncedTeamReceived], timeout: networkTimeout)
Expand Down Expand Up @@ -101,10 +98,7 @@ class DataStoreConnectionScenario2Tests: SyncEngineIntegrationTestBase {
syncUpdatedProjectReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(team)
_ = try await Amplify.DataStore.save(anotherTeam)
Expand Down Expand Up @@ -158,10 +152,7 @@ class DataStoreConnectionScenario2Tests: SyncEngineIntegrationTestBase {
}

}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

try await Amplify.DataStore.save(team)
try await Amplify.DataStore.save(project)
await fulfillment(of: [createReceived], timeout: TestCommonConstants.networkTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ class DataStoreConnectionScenario3Tests: SyncEngineIntegrationTestBase {
syncCommentReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.save(post)
await fulfillment(of: [syncedPostReceived], timeout: networkTimeout)
_ = try await Amplify.DataStore.save(comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {

}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


// Post is saved and then immediately updated
_ = try await Amplify.DataStore.save(newPost)
Expand Down Expand Up @@ -146,10 +143,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


// Post is saved and then immediately deleted
_ = try await Amplify.DataStore.save(newPost)
Expand Down Expand Up @@ -230,10 +224,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


// save the post, update and delete immediately
_ = try await Amplify.DataStore.save(newPost)
Expand Down Expand Up @@ -319,10 +310,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {

}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(newPost)
await fulfillment(of: [saveSyncReceived], timeout: networkTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ class DataStoreCustomPrimaryKeyTests: SyncEngineIntegrationTestBase {
return
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


// create customer order
_ = try await Amplify.DataStore.save(customerOrder)
Expand Down Expand Up @@ -97,10 +94,7 @@ class DataStoreCustomPrimaryKeyTests: SyncEngineIntegrationTestBase {
}

}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.save(updatedCustomerOrder)
await fulfillment(of: [updateReceived], timeout: networkTimeout)

Expand Down Expand Up @@ -138,10 +132,7 @@ class DataStoreCustomPrimaryKeyTests: SyncEngineIntegrationTestBase {
return
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.delete(CustomerOrder.self, withIdentifier: updatedCustomerOrder.id)
await fulfillment(of: [deleteReceived], timeout: networkTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(newPost)
await fulfillment(of: [createReceived], timeout: networkTimeout)
Expand Down Expand Up @@ -186,10 +183,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.save(updatedPost)
await fulfillment(of: [updateReceived], timeout: networkTimeout)

Expand All @@ -216,10 +210,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

try await Amplify.DataStore.delete(updatedPost)
await fulfillment(of: [deleteReceived], timeout: networkTimeout)
}
Expand Down Expand Up @@ -265,10 +256,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
return
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.save(newPost)
await fulfillment(of: [createReceived], timeout: networkTimeout)

Expand All @@ -295,10 +283,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
return
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.save(updatedPost, where: post.title == title)
await fulfillment(of: [updateReceived], timeout: networkTimeout)
}
Expand Down Expand Up @@ -351,10 +336,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(newPost)
await fulfillment(of: [createReceived], timeout: networkTimeout)
Expand Down Expand Up @@ -393,10 +375,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
}
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(updatedPost, where: post.content == updatedPost.content)

Expand Down Expand Up @@ -679,10 +658,7 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(newPost)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
syncedTeamReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(team)
await fulfillment(of: [syncedTeamReceived], timeout: TestCommonConstants.networkTimeout)
Expand All @@ -85,10 +82,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
}
}

guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(project)
await fulfillment(of: [syncProjectReceived], timeout: TestCommonConstants.networkTimeout)
Expand Down Expand Up @@ -132,10 +126,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
syncUpdatedProjectReceived.fulfill()
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


project.project1V2TeamId = anotherTeam.id
_ = try await Amplify.DataStore.save(project)
Expand Down Expand Up @@ -182,10 +173,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
}
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(team)
_ = try await Amplify.DataStore.save(project)
Expand All @@ -207,10 +195,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
}
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


project.name = "updatedName"
_ = try await Amplify.DataStore.save(project)
Expand All @@ -237,10 +222,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
}
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.delete(project)

// TODO: Delete Team should not be necessary, cascade delete should delete the team when deleting the project.
Expand Down Expand Up @@ -284,10 +266,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
}

}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}


_ = try await Amplify.DataStore.save(team)
_ = try await Amplify.DataStore.save(project)
Expand Down Expand Up @@ -315,10 +294,7 @@ class DataStoreConnectionScenario1V2Tests: SyncEngineIntegrationV2TestBase {
}
}
}
guard try await HubListenerTestUtilities.waitForListener(with: hubListener, timeout: 5.0) else {
XCTFail("Listener not registered for hub")
return
}

_ = try await Amplify.DataStore.delete(project)

// TODO: Delete Team should not be necessary, cascade delete should delete the team when deleting the project.
Expand Down
Loading

0 comments on commit 6c42abf

Please sign in to comment.