ravendbravendb5

RavenDB v5.4: globally wait for indices to finish before reads for integration tests


In my integration test setup entities are created using API endpoints and then that data is used by other endpoints right away.

That creates problems when an index is not up to date yet and fetching an item that was just written comes back empty.

Without adding .Customize(x => x.WaitForNonStaleResults(TimeSpan.FromSeconds(5))) to every single query, can I do something while configuring IDocumentStore globally that will force each query to wait until indices are finished writing?

I found an old answer, but that code is not valid with the current version.


Solution

  • The answer by Danielle wasn't actually solving my problem. What solved it was adding the following snippet

            var store = new DocumentStore()
            {
                Urls = new[] { RavenUrl },
                Database = TestDatabaseName,
            };
    
            // this here
            store.OnBeforeQuery += (_, beforeQueryExecutedArgs) =>
            {
                beforeQueryExecutedArgs.QueryCustomization.WaitForNonStaleResults();
            };