Reputation: 1159
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:
I tried to add
store.DatabaseCommands.DisableAllCaching();
store.Conventions.ShouldCacheRequest = _ => false;
but it didn't help.
Upvotes: 1
Views: 124
Reputation: 241525
Assuming that Controller.Post(testString)
is adding a new entry, you probably just have a stale index. In the real world, some natural amount of time would pass between post and query. In unit tests, you don't have that delay, so it's common to provide the following on your index:
.Customize(x => x.WaitForNonStaleResults())
This is not something you should do in production. You can read more in the documentation here.
Upvotes: 2