Skip to content

Save and restore the SynchronizationContext before and after each test case #2821

Description

@jnm2

One of hundreds of tests is causing System.Windows.Forms.Control.CreateHandle() which installs a WindowsFormsSynchronizationContext. When the test worker runs the next and that test happens to be async, the test deadlocks due to the fix for #2123 not being released yet. The problem is, even with the deadlock fix in NUnit, I don't want the next test running with a WindowsFormsSynchronizationContext.

Rather than locating the misbehaving test(s) through trial and error I'd rather have a failure or at least a warning of executing the work item caused an overall change to the thread's SynchronizationContext.Current. That would cause a nice todo list to fall out of my tests.

Or would we prefer to save and restore SynchronizationContext.Current with the other global state we save and restore?

Either way, we'd have to make sure that we take the snapshot before any ITestActions and other setups start and only compare or restore after they all tear down.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions