alba
alba copied to clipboard
HttpResponseBody.ReadAsText() hangs (IScenarioResult)
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);
}
Also seeing this issue, fixed it in our codebase for now
Blech, I was checked out of Alba for awhile. I'll see what I can do the next time I'm in the code.
@PhilipRRWFM I guess we could make a PR for this?