diff --git a/Objective-C/Tests/CollectionTest.m b/Objective-C/Tests/CollectionTest.m index 01723379e..7ec875d14 100644 --- a/Objective-C/Tests/CollectionTest.m +++ b/Objective-C/Tests/CollectionTest.m @@ -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; diff --git a/Objective-C/Tests/ConcurrentTest.m b/Objective-C/Tests/ConcurrentTest.m index 36af0dddc..ac7b871e2 100644 --- a/Objective-C/Tests/ConcurrentTest.m +++ b/Objective-C/Tests/ConcurrentTest.m @@ -292,7 +292,6 @@ - (void) testConcurrentCompact { }]; } -#if 0 - (void) testDatabaseChange { XCTestExpectation* exp1 = [self expectationWithDescription: @"Create"]; XCTestExpectation* exp2 = [self expectationWithDescription: @"Change"]; @@ -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"]; @@ -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