Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Jan 4, 2024
1 parent c60f716 commit d078095
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ class SyncMutationToCloudOperation: AsynchronousOperation {
}
}

/// Always retrieve and use the largest version when available. The source of the version comes
/// from either the MutationEvent itself, which represents the queue request, or the persisted version
/// from the metadata table.
///
/// **Version in the Mutation Event**. If there are mulitple mutation events pending, each outgoing
/// mutation processing will result in synchronously updating the pending mutation's version
/// before enqueuing the mutation response for reconciliation.
///
/// **Version persisted in the metadata table**: Reconciliation will persist the latest version in the
/// metadata table. In cases of quick consecutive updates, the MutationEvent's version could
/// be greater than the persisted since the MutationEvent is updated from the original thread that
/// processed the outgoing mutation.
private func getLatestVersion(_ mutationEvent: MutationEvent) -> Int? {
let latestSyncedMetadataVersion = getLatestSyncMetadata()?.version
let mutationEventVersion = mutationEvent.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import XCTest
@testable import AWSDataStorePlugin
@testable import AWSPluginsCore

// TODO: This flaky test has been disabled, tracking issue: https://github.com/aws-amplify/amplify-ios/issues/1831
// swiftlint:disable type_body_length
class MutationEventExtensionsTest: BaseDataStoreTests {

Expand All @@ -23,7 +22,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests {
/// - When: The sent model matches the received model and the first pending mutation event version is `nil`.
/// - Then: The pending mutation event version should be updated to the received model version of 1.
func testSentModelWithNilVersion_Reconciled() throws {
throw XCTSkip("TODO: fix this test")
let modelId = UUID().uuidString
let post = Post(id: modelId, title: "title", content: "content", createdAt: .now())
let requestMutationEvent = try createMutationEvent(model: post,
Expand Down Expand Up @@ -88,7 +86,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests {
/// - Then: The first pending mutation event(update) version should be updated to the received model version of 1
/// and the second pending mutation event version(delete) should not be updated.
func testSentModelWithNilVersion_SecondPendingEventNotReconciled() throws {
throw XCTSkip("TODO: fix this test")
let modelId = UUID().uuidString
let post = Post(id: modelId, title: "title", content: "content", createdAt: .now())
let requestMutationEvent = try createMutationEvent(model: post,
Expand Down Expand Up @@ -158,7 +155,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests {
/// - When: The sent model matches the received model and the first pending mutation event version is 2.
/// - Then: The first pending mutation event version should NOT be updated.
func testSentModelVersionNewerThanResponseVersion_PendingEventNotReconciled() throws {
throw XCTSkip("TODO: fix this test")
let modelId = UUID().uuidString
let post1 = Post(id: modelId, title: "title1", content: "content1", createdAt: .now())
let post2 = Post(id: modelId, title: "title2", content: "content2", createdAt: .now())
Expand Down Expand Up @@ -221,7 +217,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests {
/// - When: The sent model doesn't match the received model and the first pending mutation event version is 1.
/// - Then: The first pending mutation event version should NOT be updated.
func testSentModelNotEqualToResponseModel_PendingEventNotReconciled() throws {
throw XCTSkip("TODO: fix this test")
let modelId = UUID().uuidString
let post1 = Post(id: modelId, title: "title1", content: "content1", createdAt: .now())
let post2 = Post(id: modelId, title: "title2", content: "content2", createdAt: .now())
Expand Down Expand Up @@ -285,7 +280,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests {
/// - When: The sent model matches the received model and the first pending mutation event version is 1.
/// - Then: The first pending mutation event version should be updated to received mutation sync version i.e. 2.
func testPendingVersionReconciledSuccess() throws {
throw XCTSkip("TODO: fix this test")
let modelId = UUID().uuidString
let post1 = Post(id: modelId, title: "title1", content: "content1", createdAt: .now())
let post2 = Post(id: modelId, title: "title2", content: "content2", createdAt: .now())
Expand Down

0 comments on commit d078095

Please sign in to comment.