I've got a batch of tests that fail reliably, on 4.5.0. No issues on any prior versions, all the way back to 3.13.2.
Essentially, it seems like Tasks are not all being scheduled on the same SynchronizationContext. This manifests with a change in behavior of Task.Yield() within my tests. The tests in question are exercising a "background thread" that I have running, as part of a log batching and delivery system, and involve writing log entries to a Channel<T>, then Task.Yield()ing to ensure that whatever previously-scheduled Task continuations the "background thread" was waiting on have a chance to run, before I do assertions back in the test itself. With 4.5.0, Task.Yield() no longer guarantees that continuations that were previously waiting are actually run, suggesting that they got scheduled on a different queue than the one the test is yielding.
I managed to put together a reproduction, as minimal as I could, by trimming down the real code: https://github.com/JakenVeina/NUnitSynchronizationIssue.
Looking at the 4.5.0 release logs, I'd have to guess that this is related to #3740.
Not sure if this is really a defect in NUnit, or if I need to be doing something more explicit on my end to keep things synchronized, but if it's the latter, I'm not sure what exactly I should be doing. I understand how SynchronizationContexts work, in theory, but I've never had to actually manipulate them.
I've got a batch of tests that fail reliably, on 4.5.0. No issues on any prior versions, all the way back to 3.13.2.
Essentially, it seems like
Tasks are not all being scheduled on the sameSynchronizationContext. This manifests with a change in behavior ofTask.Yield()within my tests. The tests in question are exercising a "background thread" that I have running, as part of a log batching and delivery system, and involve writing log entries to aChannel<T>, thenTask.Yield()ing to ensure that whatever previously-scheduledTaskcontinuations the "background thread" was waiting on have a chance to run, before I do assertions back in the test itself. With 4.5.0,Task.Yield()no longer guarantees that continuations that were previously waiting are actually run, suggesting that they got scheduled on a different queue than the one the test is yielding.I managed to put together a reproduction, as minimal as I could, by trimming down the real code: https://github.com/JakenVeina/NUnitSynchronizationIssue.
Looking at the 4.5.0 release logs, I'd have to guess that this is related to #3740.
Not sure if this is really a defect in NUnit, or if I need to be doing something more explicit on my end to keep things synchronized, but if it's the latter, I'm not sure what exactly I should be doing. I understand how
SynchronizationContexts work, in theory, but I've never had to actually manipulate them.