-
Notifications
You must be signed in to change notification settings - Fork 775
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
Parallel test execution is incompatible with Micorsoft Fakes' shims #244
Comments
To sum up: I would have expected to see the exact opposite effects that you're saying you're seeing. Where is the shimming code, exactly? Is it inside the test method, or is it somewhere else? If the Fakes library uses thread locals to perform its work, and its done so in a non-TPL-compatible way, then I could see how setting Do you have a repro you can provide? |
I can reproduce this issue without using Fakes. I have just short of 2000 tests and this causes about ~560 to fail, when switching to a single thread only leaves about 50 failing (which is what I should expect). Give me to mid next week to see if I can't create a sample project. |
I figured it out. In my scenario through the use of AutoMapper and @kkm000's use of the Fakes framework, there are configuration settings held within a static variable in each of those frameworks. Tests within a single class aren't run parallelized to each other, but multiple classes are run asynchronously to each other (assuming I understand the xunit behavior correctly), which is where that static configuration gets out of sync between the multiple running classes' tests. I'll upload a sample project sometime this weekend. |
@wholroyd, I would appreciate if you do! I am swamped in other things, and I do not know when I could get back to building a minimum sample for @bradwilson. |
@kkm000, no worries. The project is at https://github.com/wholroyd/xunit.parallelization-repro and you can see here the current state of the CollectionBehaviorAttribute with DisableTestParallelization enabled with multiple tests in current execution in the test explorer... |
@kkm000 - Xunit has a few different ways of performing parallelized unit tests. Parallelization boundaries are defined by collection attributes, where collections are performed in parallel to each other. However, tests within a collection are always guaranteed to occur synchronously. If you don't utilize the collection attributes, a 'catch all' collection is used under the covers. By default, this collection is generated on a per-class basis. You can change that behavior by generating the collection at the assembly level through using this attribute instead... [assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)] This change is another option that you have if you don't want to completely de-parallelize everything and not bomb your tests. Every assembly in your solution will execute using the de facto standard of per-class, but then switch to per-assembly level collections when using this attribute on selected projects. Assemblies by default do not run in parallel to each other, but can be tweaked via Xunit config files on a per-assembly basis. I didn't see a way via attributes in code to allow this. |
There's no bug here. You're mutating shared state. That's never going to work with test parallelization. This isn't a bug with test parallelization; it's a bug with the fact that they're expecting it to work with mutable shared state. Unless you protect that mutable shared state (or get rid of it), you will be unable to parallelize tests. I'm not sure whether this truly illustrates the problem with the Fakes support or not, since I don't have source for that. I will say that, given xUnit.net's heavy reliance on |
@kkm000 - Does this issue still occur after upgrading to RC2 or later? The repro I had posted above now works as expected in the change from #276 which shipped in RC2. So the weirdness I was seeing without even using Fakes is now gone. I completely understand and agree with @bradwilson's stance on not supporting Fakes, but I'm personally just curious to see if your problem is now gone. |
I have 2 test classes using Microsoft Fakes with quite a similar setup. The following 3 lines shim a file load function and force loading of the set of fake files provided.
Another test class uses a very similar setup, shimming the same
File.Load()
function. When both tests are run, files from one shim set up end up loaded in another test (I can clearly tell that from faked file names, which differ in the tests).Is there a way to force sequential test execution?
EDIT: I tried adding
to the test assembly, but that did not change anything.
EDIT2: But
did it! Does
DisableTestParallelization
supposed to do what I think it supposed to do?The text was updated successfully, but these errors were encountered: