make sure BindDuringTcpWait_Succeeds does not run with other tests#40958
Conversation
| { | ||
|
|
||
| // Define test collection for tests to avoid all other tests. | ||
| [CollectionDefinition("NoParallelTests", DisableParallelization = true)] |
There was a problem hiding this comment.
This seems like a useful pattern to document more broadly in our "how to write unit tests for CoreFx" documentation.
There was a problem hiding this comment.
@wfurt I'm not sure this does what you want it to.
My understanding is this means that tests in this collection do not run in parallel.
By default the collections are determined by tests grouped in the same class.
So I think the effect of this change is BindDuringTcpWait_Succeeds runs in parallel with more tests.
There was a problem hiding this comment.
The trick comes from DisableParallelization = true @tmds. I was confused as well by normal documentation but the interesting part comes from https://xunit.net/releases/2.3-beta5
Added the ability to disable cross-collection parallelization for individual test collections, via the test collection definition (by setting [CollectionDefinition(DisableParallelization = true)]). Parallel-capable test collections will be run first (in parallel), followed by parallel-disabled test collections (run sequentially).
I verified that behavior and observed that my class and test will be at the end. When DisableParallelization is removed new test is mingled inside other tests. https://xunit.net/docs/running-tests-in-parallel.html does not really explain how that parameter works.
As far as the documentation: I think that needs more work in general. My plan is to wait and verify that #40475 is truly fixed and then I can update testing notes.
There was a problem hiding this comment.
Collection definition classes are intended to be empty classes. I'm not sure why you've attached this to some seemingly random existing class. Create a new empty class to attach this to instead.
There was a problem hiding this comment.
Unless I missed something It did not seems like I can attach [Collection] attribute to specific test @bradwilson. So I still needed class where test can live.
There was a problem hiding this comment.
BTW I was looking for way how to update running-tests-in-parallel.html but it does not seems it lives on github. I think the fact that DisableParallelization=true collections run at the end in sequence is crucial piece of information.
There was a problem hiding this comment.
There was a problem hiding this comment.
I meant specifically this line ([CollectionDefinition]), not the test ([Collection]).
There was a problem hiding this comment.
updated. And thanks for the doc pointer @bradwilson.
…otnet#40958) * make sure BindDuringTcpWait_Succeeds does not run with other tests * add partial to NoParallelTests class * add empty class to CollectionDefinition
…40958) * make sure BindDuringTcpWait_Succeeds does not run with other tests * add partial to NoParallelTests class * add empty class to CollectionDefinition
…otnet/corefx#40958) * make sure BindDuringTcpWait_Succeeds does not run with other tests * add partial to NoParallelTests class * add empty class to CollectionDefinition Commit migrated from dotnet/corefx@b384d34
I check run log and the test runs at the end as @bradwilson described. This should avoid conflicts with other tests.
Right now it is only one test but I put CollectionDefinition to HelperBase so it is easy to add more as we find mode cases like this.
fixes #40475