Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ef core (inmemory) issue when running all tests at once #15240

Closed
chinookproject opened this issue Apr 2, 2019 · 1 comment
Closed

Ef core (inmemory) issue when running all tests at once #15240

chinookproject opened this issue Apr 2, 2019 · 1 comment

Comments

@chinookproject
Copy link

I have a unit test project where I use the InMemory database. In that project I have three test methods. In all methods I new all classes, including my DbContext. Each DbContext has its own databaseName per test method.

Much like the docs says how to set everything up.

When I run each test individually, then it all works fine. When I run all tests at once (in parallel I guess? I'm using xunit), then only one test passes, the other two fail.

It doesn't seem like a race condition. For some reason it seems like the DbContext in the other two test methods are not saving any changes.

I have added a simplified version of our project as an attachment. You should be able to reproduce the issue with this.
EfCoreError.zip

I am really wondering, am I doing something wrong here..? Or is this a bug in EF Core?

@ajcvickers
Copy link
Member

@chinookproject What's happening here is that ProductAfname is using a generated key value. The key generator for in-memory databases is shared by multiple entity types, which means if multiple tests are run, then the key values for entities can be different compared to the case where only a single test is run. We have improved this a lot for EF Core 3.0--see #6872

The workarounds for now are to either explicitly specify the key value in the test, or to read back the generated key value and use this in the assertions.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants