Cirqus icon indicating copy to clipboard operation
Cirqus copied to clipboard

TestContext may cause deadlock

Open kimbirkelund opened this issue 8 years ago • 0 comments

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());

kimbirkelund avatar Jun 21 '16 12:06 kimbirkelund