runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Make AsyncTransactionScopeTests more "Task" friendly with await

Open jimcarley opened this issue 8 years ago • 2 comments

The AsyncTransactionScopeTests test is having deadlocking problems, possibly due to exhaustion of thread pool resources.

jimcarley avatar May 11 '18 21:05 jimcarley

dotnet/corefx#29665 has a better explanation and a description of possible fixes:

The fix is either:

Disable xunit's SynchronizationContext and parallel execution of tests, as I've done here. More of a workaround than a fix. Ensure that nothing posts back to the SynchronizationContext.Current. That means either making sure that SynchronizationContext.Current is null, e.g. by wrapping the body of each test in Task.Run so that it executes on the thread pool where there is no non-default context or by explicitly setting the SynchronizationContext to null via SetSynchronizationContext and then setting it back to xunit's context at the end of the test's execution, or by making sure even if Current is non-default that nothing looks at it, e.g. by making sure that every await on a task is attributed with .ConfigureAwait(false). Avoid the synchronous blocking in the first place, e.g. by replacing all .Result, .Wait, .WaitAll usage with awaits, and making the tests async all the way up to the xunit test level. This is generally what we do in corefx tests.

jimcarley avatar May 11 '18 21:05 jimcarley

Done with PR - https://github.com/dotnet/corefx/pull/29901

jimcarley avatar May 25 '18 17:05 jimcarley