I am working on WebAPI application using RavenDB. I have a couple of XUnit tests which have kind of a similar outline:
var checkQuery = session.Query<Resource>().Where(x => x.AliasIds.Any(a => a == alias.Id));
PAssert.Throws<InvalidOperationException>(() => checkQuery.Single());
var testString = Guid.NewGuid().ToString();
Controller.Post(testString);
var res = checkQuery.Single();
PAssert.IsTrue(() => res != null);
What happens is that when I have multiple tests run at the same time they fail at the line
var res = checkQuery.Single();
With exception:
Result Message: System.InvalidOperationException : Sequence contains no elements
What I have found:
- It works fine if I got first call to checkQuery.Single() commented.
- It works fine if I add Thread.Sleep(1000) before problematic line.
I tried to add
store.DatabaseCommands.DisableAllCaching();
store.Conventions.ShouldCacheRequest = _ => false;
but it didn't help.