From ee8b753424854cf70f0a923f68d54125c058b832 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Thu, 8 Aug 2024 17:19:04 +0300 Subject: [PATCH] CBL-6140: Add testConcurrentCreateAndQuery to verify query's lock (#3319) --- Objective-C/Tests/ConcurrentTest.m | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Objective-C/Tests/ConcurrentTest.m b/Objective-C/Tests/ConcurrentTest.m index 36af0dddc..3c47697a1 100644 --- a/Objective-C/Tests/ConcurrentTest.m +++ b/Objective-C/Tests/ConcurrentTest.m @@ -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