Reputation: 3771
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
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
Reputation: 3839
Use this convention on the document store:
i.e.:
using var store = new DocumentStore
{
Database = database,
Urls = new[] { server.WebUrl },
Conventions = new DocumentConventions { WaitForNonStaleResultsTimeout = TimeSpan.FromSeconds(25) }
}.Initialize();
Upvotes: 1