Cirqus
Cirqus copied to clipboard
TestContext may cause deadlock
When using the TestContext there is a risk of hangs when WaitForViewsToCatchUp is called. This is the case both when called from within TestContext, when running in sync mode, and when called from outside.
The issue arises when a view uses async/await in its WaitUntilProcessed implementation - possibly only when using ConfigureAwait(false). When TestContext.WaitForViewsToCatchUp calls Wait() it hangs because using Wait() doesn't play nice with async/await.
A workaround might be to wrap the call to Wait() in Task.Run() and call Wait() on the resulting Task. As in: Task.Run(() => otherTask.Wait()).Wait()
.
The relevant code lines in TestContext are line 264:
WithEventDispatcherOfType<IAwaitableEventDispatcher>(x => x.WaitUntilProcessed(result, TimeSpan.FromSeconds(timeoutSeconds)).Wait());
and line 278:
WithEventDispatcherOfType<IAwaitableEventDispatcher>(x => x.WaitUntilProcessed<TViewInstance>(result, TimeSpan.FromSeconds(timeoutSeconds)).Wait());