Unpredictable Full Text Sear responses from QueryAsync

I’m experiencing strange issue .QueryAsync() when running xUnit unit (integration) tests in Visual Studio, it gives unpredictable results. When I run all 10 tests, some of them randomly fail, because .QueryAsync comes back with empty results, despite the fact that documents are in the database.

More detailed information:
Enterprise Edition 6.0.1 build 2037 ‧ IPv4.
CouchbaseNetClient 2.7.16
Couchbase.Extensions.DependencyInjection 2.0.2

I have 10 xUnit tests that I run from Visual Studio for ASP.NET CORE Web API application. Each tests inserts the test documents into Couchbase (Each document inserted into database has unique ID. Documents have schema, but values are randomly generated.), followed by the call to the controller.
Controller is D. Injected with Singleton Service class

public RegistrationDataServices(CouchbaseConfig couchBaseConfig, IBucketProvider bucketProvider, EnrollmentStatus enrollmentStatus)

RegistrationDataServices class has number of methods that each create is own bucket var bucket = bucketProvider.GetBucket("BucketName" ); (bucketProvider is Dependency Injected into RegistrationDataServices through .AddCouchbase(Configuration.GetSection("Couchbase")); ) followed by forming full text search:

secondFTSResult = await bucket.QueryAsync(new SearchQuery
Index = dbConfig.FTS_Index,
Query = new BooleanQuery().Must(ftsMustField.ToArray()).Should(ftsShouldFields.ToArray()).ShouldMin(0),
SearchParams = new SearchParams()

After that I retrieve document by their IDs and serialize them into class:

var ftsAdrResult =
(await bucket.GetDocumentsAsync(secondFTSResult.Select(x => x.Id)))
.Select(x => JsonConvert.DeserializeObject(x.Content)).ToList();
At the end of each unit test documents are removed from the database.

If I ran all 10 tests, sometimes they all pass, but often some of them will randomly fail - no data is returned from the database. However, if I reran failed tests individually, they work fine.

They only thing I could think of, is that dB doesn’t have enough time to index the data before querying, so I have placed await Task.Delay(TimeSpan.FromSeconds(25)); to make sure documents are index. That doesn’t fix the issue.
Or there is some kind of synchronization issues ?
RegistrationDataServices methods don’t share any information with each other, apart from IBucketProvider bucketProvider
Thank you !

Hi @adorfman,

My initial guess is similar to yours: async .net code plus (I assume) async Couchbase data inserts plus async Couchbase index updates, so maybe some sort of race condition. Do you think you could share a minimum version of your project so that we could try to investigate and reproduce on our own?