Skip to content

Commit 327e451

Browse files
authored
chore(datastore): Add stress tests for Datastore category (#2639)
* chore(datastore): Add stress tests for Datastore category * Add separate resources and test target for stress tests in CI/CD * Address review comments * Address review comments * Address review comments
1 parent 64e51c4 commit 327e451

File tree

11 files changed

+742
-100
lines changed

11 files changed

+742
-100
lines changed

AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginIntegrationTests/DataStoreEndToEndTests.swift

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -479,106 +479,6 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase {
479479
try await Amplify.DataStore.start()
480480
}
481481

482-
/// Perform concurrent saves and observe the data successfuly synced from cloud. Then delete the items afterwards
483-
/// and ensure they have successfully synced from cloud
484-
///
485-
/// - Given: DataStore is in ready state
486-
/// - When:
487-
/// - Concurrently perform Save's
488-
/// - Then:
489-
/// - Ensure the expected mutation event with version 1 (synced from cloud) is received
490-
/// - Clean up: Concurrently perform Delete's
491-
/// - Ensure the expected mutation event with version 2 (synced from cloud) is received
492-
///
493-
func testConcurrentSave() async throws {
494-
await setUp(withModels: TestModelRegistration(), logLevel: .verbose)
495-
try await startAmplifyAndWaitForSync()
496-
497-
var posts = [Post]()
498-
let count = 2
499-
for index in 0 ..< count {
500-
let post = Post(title: "title \(index)",
501-
content: "content",
502-
createdAt: .now())
503-
posts.append(post)
504-
}
505-
let postsSyncedToCloud = expectation(description: "All posts saved and synced to cloud")
506-
postsSyncedToCloud.expectedFulfillmentCount = count
507-
log.debug("Created posts: [\(posts.map { $0.identifier })]")
508-
509-
let postsCopy = posts
510-
Task {
511-
var postsSyncedToCloudCount = 0
512-
let mutationEvents = Amplify.DataStore.observe(Post.self)
513-
do {
514-
for try await mutationEvent in mutationEvents {
515-
guard postsCopy.contains(where: { $0.id == mutationEvent.modelId }) else {
516-
return
517-
}
518-
519-
if mutationEvent.mutationType == MutationEvent.MutationType.create.rawValue,
520-
mutationEvent.version == 1 {
521-
postsSyncedToCloudCount += 1
522-
self.log.debug("Post saved and synced from cloud \(mutationEvent.modelId) \(postsSyncedToCloudCount)")
523-
postsSyncedToCloud.fulfill()
524-
}
525-
}
526-
} catch {
527-
XCTFail("Failed \(error)")
528-
}
529-
}
530-
531-
let capturedPosts = posts
532-
533-
DispatchQueue.concurrentPerform(iterations: count) { index in
534-
Task {
535-
_ = try await Amplify.DataStore.save(capturedPosts[index])
536-
}
537-
}
538-
await waitForExpectations(timeout: 100)
539-
540-
let postsDeletedLocally = expectation(description: "All posts deleted locally")
541-
postsDeletedLocally.expectedFulfillmentCount = count
542-
543-
let postsDeletedFromCloud = expectation(description: "All posts deleted and synced to cloud")
544-
postsDeletedFromCloud.expectedFulfillmentCount = count
545-
546-
Task {
547-
var postsDeletedFromCloudCount = 0
548-
let mutationEvents = Amplify.DataStore.observe(Post.self)
549-
do {
550-
for try await mutationEvent in mutationEvents {
551-
guard capturedPosts.contains(where: { $0.id == mutationEvent.modelId }) else {
552-
return
553-
}
554-
555-
if mutationEvent.mutationType == MutationEvent.MutationType.delete.rawValue,
556-
mutationEvent.version == 1 {
557-
self.log.debug(
558-
"Post deleted locally \(mutationEvent.modelId)")
559-
postsDeletedLocally.fulfill()
560-
} else if mutationEvent.mutationType == MutationEvent.MutationType.delete.rawValue,
561-
mutationEvent.version == 2 {
562-
postsDeletedFromCloudCount += 1
563-
self.log.debug(
564-
"Post deleted and synced from cloud \(mutationEvent.modelId) \(postsDeletedFromCloudCount)")
565-
postsDeletedFromCloud.fulfill()
566-
}
567-
}
568-
} catch {
569-
XCTFail("Failed \(error)")
570-
}
571-
}
572-
573-
DispatchQueue.concurrentPerform(iterations: count) { index in
574-
Task {
575-
try await Amplify.DataStore.delete(capturedPosts[index])
576-
}
577-
}
578-
579-
await waitForExpectations(timeout: 100)
580-
}
581-
582482
// MARK: - Helpers
583483

584484
func validateSavePost() async throws {

0 commit comments

Comments
 (0)