【发布时间】:2013-08-02 11:46:45
【问题描述】:
我们正在升级到 RavenDB 2.5 并遇到了特殊情况。 我们的一个单元测试突然失败了,原因不明。
这里有一些简单的代码来重现这个问题:
class Foo
{
public Guid Id { get; private set; }
public DateTime? ExpirationTime { get; set; }
public Foo()
{
Id = Guid.NewGuid();
ExpirationTime = null;
}
}
var documentStore = new EmbeddableDocumentStore
{
RunInMemory = true,
Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites }
};
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
session.Store(new Foo());
session.Store(new Foo());
session.SaveChanges();
}
所以,现在我们在数据库中有两个文档,它们的 ExpirationTime = null。 这是在数据库中查询这些文档时发生的情况:
using (var session = documentStore.OpenSession())
{
var bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null).ToList();
Console.WriteLine("1. Number of documents: {0}", bar.Count);
bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null ||
foo.ExpirationTime > DateTime.Now).ToList();
Console.WriteLine("2. Number of documents: {0}", bar.Count);
bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null |
foo.ExpirationTime > DateTime.Now).ToList();
Console.WriteLine("3. Number of documents: {0}", bar.Count);
}
这些查询的输出如下:
1. Number of documents: 2
2. Number of documents: 0
3. Number of documents: 2
这对我来说似乎不正确......我也希望数字 2. 给出 2。
我对 RavenDB 服务器运行了相同的查询,得到了预期的结果,所以这似乎是 EmbeddableDocumentStore 的问题。
在对此进行测试时,我还发现在其他情况下使用逻辑或运算符时会出现一些奇怪的行为。有时使用foo.HasValue 会得到与foo != null 不同的结果,但这可能与同一个问题有关。
还有其他人遇到过这个问题吗?已知错误?
【问题讨论】:
-
RavenDb : Force indexes to wait until not stale whilst unit testing 可以是
stale index吗? -
@NoLifeKing 我没有在示例代码中显示它,但我在单元测试时总是使用
DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites或WaitForNonStaleResultsAsOfLastWrite()。在升级到 Raven 2.5 之前,这也按预期工作。 -
请将失败的单元测试发送到邮件列表
-
@AyendeRahien 我刚刚做了 :-)