使用RavenDb进行单元测试时,通常会检索或以其他方式处理新添加的数据.这可能导致"陈旧索引"例外,例如
Bulk operation cancelled because the index is stale and allowStale is false
Run Code Online (Sandbox Code Playgroud)
根据一些答案
强制数据库(IDocumentStore实例)在处理查询或批处理操作之前等待其索引未过时的方法是DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites在IDocumentStore初始化期间使用,如下所示:
public class InMemoryRavenSessionProvider : IRavenSessionProvider
{
private static IDocumentStore documentStore;
public static IDocumentStore DocumentStore
{
get { return (documentStore ?? (documentStore = CreateDocumentStore())); }
}
private static IDocumentStore CreateDocumentStore()
{
var store = new EmbeddableDocumentStore
{
RunInMemory = true,
Conventions = new DocumentConvention
{
DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites,
IdentityPartsSeparator = "-"
}
}; …Run Code Online (Sandbox Code Playgroud)