LLL
LLL

Reputation: 3771

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.

Upvotes: 1

Views: 36

Answers (2)

LLL
LLL

Reputation: 3771

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

Upvotes: 0

Danielle
Danielle

Reputation: 3839

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();

Upvotes: 1

Related Questions