Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:25:27+00:00 2026-05-28T17:25:27+00:00

I am using RavenDB in In-Memory mode for unit testing. My queries are backed

  • 0

I am using RavenDB in In-Memory mode for unit testing. My queries are backed by static indexes. I am not using WaitForNonStaleResults() API (nor do I want to).

Typical workflow for a test is:

  1. Initialise RavenDB in In-Memory mode
  2. Integrate indexes using IndexCreation.CreateIndexes(Assembly, IDocumentStore)
  3. Insert test data (for verifying query behaviour)
  4. Run query
  5. Verify query output

I have noticed steps 1-3 happen so quickly, that static indexes don’t have time to get updated before step 4 – therefore the indexes are stale.

I have created a quick work-around for this. After step 3, I execute:

while (documentStore.DocumentDatabase.Statistics.StaleIndexes.Length != 0)
    Thread.Sleep(10);

This feels cumbersome. What I would like to know is:

  • Is it normal for indexes to be stale when running RavenDB in In-Memory mode?
  • Is there a better way to avoid stale indexes during testing?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:25:29+00:00Added an answer on May 28, 2026 at 5:25 pm

    Cross-posted this to RavenDB usergroup and have a working solution.

    Is it normal for indexes to be stale when running RavenDB in In-Memory
    mode?

    Yes. An index is an index.

    Is there a better way to avoid stale indexes during testing?

    Yes. Configure global conventions when initialising document store:

    var store = new EmbeddableDocumentStore();
    store.RunInMemory = true;
    store.Conventions = new DocumentConvention
    {
        DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites
    };
    
    store.Initialize();
    

    Note: ConsistencyOptions.QueryYourWrites doesn’t work with Map/Reduce indexes, i.e. indexes with a Reduce => ... section. For these you have to use Customize(x => x.WaitForNonStale...()) when querying

    Update: There is another approach, which may be better (haven’t personally tried it yet). You could implement IDocumentQueryListener to force all queries to return non-stale results:

    var store = new EmbeddableDocumentStore { RunInMemory = true };
    store.Initialize();
    
    store.RegisterListener(new ForceNonStaleQueryListener());
    
    public class ForceNonStaleQueryListener : IDocumentQueryListener
    {
        public void BeforeQueryExecuted(IDocumentQueryCustomization customization)
        {
            queryCustomization.WaitForNonStaleResults();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having Trouble setting up an in memory database using RavenDB. The error I
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am playing with the idea of using RavenDB as the data store for
So I installed RavendDB on a Win2003 server using these instructions: http://old.ravendb.net/documentation/docs-deployment-iis And i
I am thinking/evaluating of using RavenDB for the enterprise application our company is planning
I have successfully issued a Start-Backup request to my local RavenDB using an asynchronous
I'm using ravendb to serialize an object and test it through mstest. I am
I have some behavior that I don't understand. I'm using RavenDB, and I'm using
Using report builder 3.0, I have a report that queries a cube. How do
The question I have is that of securing documents across services using RavenDb and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.