Skip to content

Commit

Permalink
CBL-6147: Add testConcurrentCreateAndQuery to verify query's lock (#3321
Browse files Browse the repository at this point in the history
)

* CBL-6140: Add testConcurrentCreateAndQuery to verify query's lock (#3319)

* enable testDatabaseChange and testDocumentChange

* fix testUseInvalidCollection for build
  • Loading branch information
velicuvlad authored Aug 13, 2024
1 parent 00e5433 commit c2e3d73
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Objective-C/Tests/CollectionTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ - (void) testUseInvalidCollection: (NSString*)collectionName onAction: (void (^)

// get index, get indexes, delete index
[self expectError: CBLErrorDomain code: CBLErrorNotOpen in: ^BOOL(NSError** err) {
return [col indexWithName: @"index1" error: err];
return [col indexWithName: @"index1" error: err] != nil;
}];
[self expectError: CBLErrorDomain code: CBLErrorNotOpen in: ^BOOL(NSError** err) {
return [col indexes: err] != nil;
Expand Down
39 changes: 33 additions & 6 deletions Objective-C/Tests/ConcurrentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ - (void) testConcurrentCompact {
}];
}

#if 0
- (void) testDatabaseChange {
XCTestExpectation* exp1 = [self expectationWithDescription: @"Create"];
XCTestExpectation* exp2 = [self expectationWithDescription: @"Change"];
Expand All @@ -302,15 +301,13 @@ - (void) testDatabaseChange {
}];

[self concurrentRuns: 1 waitUntilDone: NO withBlock: ^(NSUInteger rIndex) {
[_db saveDocument: [[CBLMutableDocument alloc] initWithID: @"doc1"] error: nil];
[self->_db saveDocument: [[CBLMutableDocument alloc] initWithID: @"doc1"] error: nil];
[exp1 fulfill];
}];

[self waitForExpectations: @[exp2] timeout: 10.0]; // Test deadlock
}
#endif //TEMP

#if 0 //TEMP
- (void) testDocumentChange {
XCTestExpectation* exp1 = [self expectationWithDescription: @"Create"];
XCTestExpectation* exp2 = [self expectationWithDescription: @"Change"];
Expand All @@ -320,13 +317,43 @@ - (void) testDocumentChange {
}];

[self concurrentRuns: 1 waitUntilDone: NO withBlock: ^(NSUInteger rIndex) {
[_db saveDocument: [[CBLMutableDocument alloc] initWithID: @"doc1"] error: nil];
[self->_db saveDocument: [[CBLMutableDocument alloc] initWithID: @"doc1"] error: nil];
[exp1 fulfill];
}];

[self waitForExpectations: @[exp2] timeout: 10.0]; // Test deadlock
}
#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

Expand Down

0 comments on commit c2e3d73

Please sign in to comment.