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

29 Views Asked by At

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.

2

There are 2 best solutions below

0
LLL On BEST ANSWER

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();
        };
1
Danielle On

Use this convention on the document store:

https://ravendb.net/docs/article-page/5.4/Csharp/client-api/configuration/conventions#waitfornonstaleresultstimeout

i.e.:

using var store = new DocumentStore
{
   Database = database,
   Urls = new[] { server.WebUrl },
   Conventions = new DocumentConventions { WaitForNonStaleResultsTimeout = TimeSpan.FromSeconds(25) }
}.Initialize();