My team is utilizing this [email protected] to run an in-memory test server for our E2E tests. While debugging tests, I've observed that most of the time, tests that utilize the server hang and the requests are never received by the web controllers. Debugging led me to OwinClientHandler where I saw:
state.OwinContext.Request.Body = body;
CancellationTokenRegistration registration = cancellationToken.Register(state.Abort);
// Async offload, don't let the test code block the caller.
Task offload = Task.Factory.StartNew(async () =>
{
try
{
await _next(state.Environment);
state.CompleteResponse();
}
catch (Exception ex)
{
state.Abort(ex);
}
finally
{
registration.Dispose();
state.Dispose();
}
});
return await state.ResponseTask;
When the test hangs, the breakpoint set at await _next(state.Environment); is never hit. When it does not hang, the breakpoint is hit, and then subsequently the web controller breakpoint is hit. I'm not familiar with Task.Factory.StartNew but it seems like there might be a bug here based on some quick google searches. There's mentions that StartNew does not understand async delegates, and that a call to Unwrap() is necessary, or use Task.Run instead. https://sergeyteplyakov.github.io/Blog/async/2019/05/21/The-Dangers-of-Task.Factory.StartNew.html
My team is utilizing this [email protected] to run an in-memory test server for our E2E tests. While debugging tests, I've observed that most of the time, tests that utilize the server hang and the requests are never received by the web controllers. Debugging led me to OwinClientHandler where I saw:
When the test hangs, the breakpoint set at
await _next(state.Environment);is never hit. When it does not hang, the breakpoint is hit, and then subsequently the web controller breakpoint is hit. I'm not familiar withTask.Factory.StartNewbut it seems like there might be a bug here based on some quick google searches. There's mentions thatStartNewdoes not understand async delegates, and that a call toUnwrap()is necessary, or useTask.Runinstead. https://sergeyteplyakov.github.io/Blog/async/2019/05/21/The-Dangers-of-Task.Factory.StartNew.html