Skip to content

Commit

Permalink
CBL-6140: Add testConcurrentCreateAndQuery to verify query's lock (#3319
Browse files Browse the repository at this point in the history
)
  • Loading branch information
velicuvlad authored Aug 8, 2024
1 parent 5c10248 commit ee8b753
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Objective-C/Tests/ConcurrentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,37 @@ - (void) testDocumentChange {
}
#endif

- (void) testConcurrentCreateAndQuery {
NSError* outError;
const NSUInteger kNDocs = 10;
const NSUInteger kNConcurrents = 3;
__block NSArray* allObjects= @[];

NSString* queryString = @"SELECT * FROM _";
CBLQuery* query = [self.db createQuery: queryString error: &outError];


[self concurrentRuns: kNConcurrents waitUntilDone: YES withBlock: ^(NSUInteger rIndex) {
NSError* error;
if (rIndex % 2 == 0){
[self.db inBatch: &error usingBlock: ^{
NSError* err;
Assert([self createAndSaveDocs: kNDocs error: &err],
@"Error creating docs: %@", err);
CBLQueryResultSet* rs = [query execute: &err];
allObjects = rs.allObjects;
}];
} else {
Assert([self createAndSaveDocs: kNDocs error: &error],
@"Error creating docs: %@", error);
CBLQueryResultSet* rs = [query execute: &error];
allObjects = rs.allObjects;
}

}];
AssertEqual(self.db.count, allObjects.count);
}

#pragma clang diagnostic pop

@end

0 comments on commit ee8b753

Please sign in to comment.