4

We are in the process of upgrading to RavenDB 2.5 and have run into a peculiar situation. One of our unit tests is suddenly failing, and for no obvious reason.

Here is some simple code to reproduce the issue:

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();
}

So, now we have two documents in the database, both with ExpirationTime = null. This is what happens when querying the database for these documents:

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);        
}

The output from these queries are as follows:

1. Number of documents: 2
2. Number of documents: 0
3. Number of documents: 2

This doesn't seem correct to me... I would expect also number 2. to give 2.

I ran the same queries against a RavenDB server, and got the expected results, so it seems like this is an issue with the EmbeddableDocumentStore.

While testing this I also found some strange behavior when using the logical or operator in other cases. Sometimes using foo.HasValue would give different result than foo != null, but that might be related to the same issue.

Anyone else that have experienced this problem? Known bug?

Nils Magne Lunde
  • 1,794
  • 1
  • 13
  • 21
  • [RavenDb : Force indexes to wait until not stale whilst unit testing](http://stackoverflow.com/questions/10316721/ravendb-force-indexes-to-wait-until-not-stale-whilst-unit-testing) Could it be something with a `stale index`? – NoLifeKing Aug 02 '13 at 11:53
  • @NoLifeKing I was not showing it in the example code, bu I always use either `DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites` or `WaitForNonStaleResultsAsOfLastWrite()` when unit testing. Also this did work as expected before upgrading to Raven 2.5. – Nils Magne Lunde Aug 02 '13 at 12:03
  • 1
    Please send a failing unit test to the mailing list – Ayende Rahien Aug 02 '13 at 13:08
  • @AyendeRahien I just did :-) – Nils Magne Lunde Aug 03 '13 at 22:00

1 Answers1

3

This was a bug in RavenDB related to sorting on null fields. Fixed in the next build

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41