-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: update to xunit 2 #1380
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
chore: update to xunit 2 #1380
Conversation
| int thisThread = Thread.CurrentThread.ManagedThreadId; | ||
|
|
||
| Task.Run(() => { | ||
| await Task.Run(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't that stable locally, but doing async/await rather than Wait() seemed to make it happier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, calling Wait is a big no-no. See here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, hadn't seen that, but does explain things! I think this was the only consistent deadlock, so hopefully we're not doing it elsewhere!
|
|
||
| var obs = activation.GetActivationForView(uc); | ||
| var activated = obs.CreateCollection(); | ||
| var activated = obs.CreateCollection(scheduler: ImmediateScheduler.Instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the feeling this shouldn't be necessary, but it looks like the way RxApp works, sometimes MainThreadScheduler might not be set as ImmediateScheduler in unit tests (we set _MainThreadScheduler but _UnitTestScheduler wins in general).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is the exact problem I ran into with the SchedulerShouldBeCurrentThreadInTestRunner test under NCrunch. I dream of a day we can completely remove ambient contexts from ReactiveUI.
| @@ -0,0 +1,3 @@ | |||
| using Xunit; | |||
|
|
|||
| [assembly: CollectionBehavior(DisableTestParallelization = true, MaxParallelThreads = 1)] | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to make xunit2 behave more like xunit 1.
|
This LGTM @olevett! Using Test Explorer, I can build and successfully run all tests (assuming I unload the Events* and AndroidSupport projects, since they fail to build on my machine). What's interesting is that NCrunch seems to be working much better, too. I had to update the config (which I can PR separately once this is merged), but now only one test fails. And the test in question is |
|
Ugh, I wanted to merge this, but build is failing with OpenCover error now. Am guessing it's an intermittent problem. I don't think there's an easy way for me to just force another build 🤔 Maybe @ghuntley can chime in? |
|
That test seems to be the most flakey of the lot, but also, if it's not working possibly a lot of other tests won't behave quite right. Will spend some more time digging at it, unless anyone has better ideas! |
|
Wow, the
I'm 99% sure the bug is in the static ctor. Instead of assigning to Will also dig a bit further... |
|
I'm wondering if part of this is due to the ThreadStatic I'm not entirely sure if the ThreadStatic stuff actually makes that much sense with schedulers as Also, I think |
|
As a quick test of building etc, I've disabled the scheduler test that's failing - I don't think this is great (either we should fix it or 🔥 it) but I want to make sure CI can consistently build and run the other tests... |
4a1bc5f to
9896022
Compare
d2f569c to
0820e2e
Compare
11ea79a to
964400c
Compare
|
As per suggestion from @kentcb I've been skipping most tests and then incrementally adding them back in. I've been using a quick extra build process to run tests 10 times locally which should hopefully catch out any intermittent failures, I've included this as cake task called |
|
@olevett I had a crazy idea that I was gonna try, but haven't had the time...it may not work, but let me run it by you in case it helps. I was thinking I'd add a console app to the solution, it would reference unit tests. The console app would:
Thus we'd whittle down the tests to a very small set that fail when executed together. It's not perfect, I know, but it could be an automated way to whittle the situation down to just a handful of tests quite quickly. Anyway, just an idea that may amount to nothing, but thought I'd pass it on since it's unlikely I'm going to find the time to do this myself. |
|
@kentcb tht sounds like a neat solution, at the moment I've got a cake build that does the iterations part (the easy bit!)
My one concern would be the test that causes issues might be a passing test, so only running failing tests might not pick it up correctly. Not sure if that’s a valid concern.
|
Yeah, that's why I'm suggesting to find groups of tests where any test within the group fails (didn't word that very clearly initially). And the randomisation gives ample opportunity to find combinations of tests that might all pass individually, but not when executed together. Ultimately, if this automation could narrow down to a small set of e.g. 10 or so tests (or even 2!) that cannot be executed together without occasional failures, would save a lot of your time. |
| public class TestUtilsTest | ||
| { | ||
| [Fact] | ||
| public async Task WithAsyncScheduler() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test just seemed to break everything... I'm not even really sure what it's testing, so thought losing it seemed safest...
| public class TestUtilsTest | ||
| { | ||
| [Fact] | ||
| public async Task WithAsyncScheduler() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test just seemed to break everything... I'm not even really sure what it's testing, so thought losing it seemed safest...
d4d9fc2 to
463c3cc
Compare
|
I think this is getting pretty near to being reliable, if anyone's interested in the breakdown or a build script that thrashes the tests a few times to pick up threading quirks, there's a branch hhere but I've squashed down to reduce the noise a bit. |
6e6dd89 to
2c1acea
Compare
2c1acea to
663fa00
Compare
|
Rebased because file header changes confused git... |

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Fixes #1301
What is the current behavior? (You can also link to an open issue here)
Uses xunit 1.9.x
What is the new behavior (if this is a feature change)?
Use xunit 2.x
Does this PR introduce a breaking change?
Unlikely, this shouldn't be being consumed by end users anyway.
Please check if the PR fulfills these requirements
Other information:
The biggest change that impacts this is the threading model for xunit 2 has changed a bit, so some tests are marked as STA or WPF which ensures they're running on the right thread.
I'm a little concerned the tests could be a bit flaky because of the changes, so one thing I'm keen for this PR to do is build it on a different machine.
If tests are flaky, we might need to either rework them a bit, possibly doing one of the following