Skip to content

Task Synchronization Issue after upgrading to 4.5.0 #5137

@JakenVeina

Description

@JakenVeina

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions