dotnet / dotnet/aspnetcore

Requests to TestHost do not await the `RequestEnd` diagnostic events.

Open
#5,916 6 comments 0 reactions 0 assignees View on GitHub
affected-very-few area-hosting area-networking bug severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

[I'm writing an OpenTracing instrumentation library](https://github.com/opentracing-contrib/csharp-netcore) that uses the BeginRequest/RequestEnd `DiagnosticSource` events and I'd like to use `TestHost` to write some unit/integration tests.

However, it seems like the HttpClient currently only awaits the response and it doesn't wait until _application.DisposeContext() is called (which then creates the DiagnosticSource events).

https://github.com/aspnet/Hosting/blob/a041b368bb18a00e4c05c6de36928cf0174a6f60/src/Microsoft.AspNetCore.TestHost/HttpContextBuilder.cs#L70-L71

As `TestHost` is for testing the server, it would be great if the client would wait until the request is 100% processed on the server. I currently have to wait/poll a little bit until the underlying task is actually finished.

Would you accept a PR for this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.