RavenDB EmbeddableDocumentStore 可能存在漏洞

4
我们正在升级到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。

我在RavenDB服务器上运行了相同的查询,并获得了预期的结果,因此看起来这是EmbeddableDocumentStore的问题。

在测试过程中,我还发现在其他情况下使用逻辑或运算符时会出现一些奇怪的行为。有时使用foo.HasValue会给出与foo != null不同的结果,但这可能与同一问题有关。

还有其他人遇到这个问题吗?已知的错误吗?


RavenDb:在单元测试期间强制索引等待直到不过时这可能与“过时的索引”有关吗? - NoLifeKing
@NoLifeKing,我在示例代码中没有展示它,但我在单元测试时总是使用DefaultQueryingConsistency = ConsistencyOptions.QueryYourWritesWaitForNonStaleResultsAsOfLastWrite()。在升级到Raven 2.5之前,这也按预期工作。 - Nils Magne Lunde
1
请将一个失败的单元测试发送到邮件列表中。 - Ayende Rahien
@AyendeRahien 我刚刚做了 :) - Nils Magne Lunde
1个回答

3

这是RavenDB中与空字段排序相关的一个错误。 在下个版本中得到修复。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接