Skip to content

Commit

Permalink
Fix flaky testCollectionConflictResolver (#3231)
Browse files Browse the repository at this point in the history
Fixed the condition check whether the document replication should report conflict error or not.
  • Loading branch information
pasin authored Feb 17, 2024
1 parent cb9878a commit 7d61e40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions Objective-C/Tests/ReplicatorTest+Collection.m
Original file line number Diff line number Diff line change
Expand Up @@ -920,19 +920,17 @@ - (void) testCollectionConflictResolver {

CBLReplicator* r = [[CBLReplicator alloc] initWithConfig: config];
id token = [r addDocumentReplicationListener: ^(CBLDocumentReplication* docReplication) {
// change with single document are the update revisions from colA & colB collections.
if (docReplication.documents.count == 1) {
if (!docReplication.isPush) {
// Pull will resolve the conflicts:
CBLReplicatedDocument* doc = docReplication.documents[0];
AssertEqualObjects(doc.id, [doc.collection isEqualToString: @"colA"] ? @"doc1" : @"doc2");
AssertEqual(doc.error.code, 0);
} else if (docReplication.documents.count == 2) {
// change with 2 docs, will be the conflict
} else {
// Push will have conflict errors:
for (CBLReplicatedDocument* doc in docReplication.documents) {
AssertEqualObjects(doc.id, [doc.collection isEqualToString: @"colA"] ? @"doc1" : @"doc2");
AssertEqual(doc.error.code, CBLErrorHTTPConflict);
}
} else {
AssertFalse(true, @"Unexpected document change listener");
}
}];
[self runWithReplicator: r errorCode: 0 errorDomain: nil];
Expand Down
10 changes: 4 additions & 6 deletions Swift/Tests/ReplicatorTest+Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -640,20 +640,18 @@ class ReplicatorTest_Collection: ReplicatorTest {

let r = Replicator(config: config)
r.addDocumentReplicationListener { docReplication in
if docReplication.documents.count == 1 {
// change with single doc, will be update revisions from colA & colB collections.
if !docReplication.isPush {
// Pull will resolve the conflicts:
let doc = docReplication.documents[0]
XCTAssertEqual(doc.id, doc.collection == "colA" ? "doc1" : "doc2")
XCTAssertNil(doc.error)

} else if docReplication.documents.count == 2 {
// change with 2 docs, will be the conflict change
} else {
// Push will have conflict errors:
for doc in docReplication.documents {
XCTAssertEqual(doc.id, doc.collection == "colA" ? "doc1" : "doc2")
XCTAssertEqual((doc.error as? NSError)?.code, CBLError.httpConflict)
}
} else {
XCTFail("Unexpected document change listener")
}
}
run(replicator: r, expectedError: nil)
Expand Down

0 comments on commit 7d61e40

Please sign in to comment.