The HttpResponseBody(IScenarioResult).ReadAsText method hangs when using AlbaHost in the context of SpecFlow, with an async step implementation. Specifically, when attempting to copy the response body stream (of type ResponseBodyReaderStream), marked in the source snippet below.
The implementation of ResponseBodyReaderStream.Read method in turn contains a call with .GetAwaiter().GetResult();. This may be the reason for the copy operation hanging.
Solved outside the AlbaHost source base for now, by calling the Context.Response.Body.CopyToAsync(stream); method instead.
```
/// <summary>
/// Read the contents of the HttpResponse.Body as text
/// </summary>
/// <returns></returns>
public string ReadAsText()
{
return Read(s => s.ReadAllText());
}
public T Read<T>(Func<Stream, T> read)
{
if (Context.Response.Body.CanSeek || Context.Response.Body is MemoryStream)
{
Context.Response.Body.Position = 0;
}
else
{
var stream = new MemoryStream();
Context.Response.Body.CopyTo(stream); <--- hangs
stream.Position = 0;
Context.Response.Body = stream;
}
return read(Context.Response.Body);
}
The
HttpResponseBody(IScenarioResult).ReadAsText
method hangs when using AlbaHost in the context of SpecFlow, with an async step implementation. Specifically, when attempting to copy the response body stream (of typeResponseBodyReaderStream
), marked in the source snippet below.The implementation of
ResponseBodyReaderStream.Read
method in turn contains a call with.GetAwaiter().GetResult();
. This may be the reason for the copy operation hanging.Solved outside the AlbaHost source base for now, by calling the Context.Response.Body.CopyToAsync(stream); method instead.