Improve .NET 8 metrics tests
Bug Report
Symptom
The tests added in https://github.com/open-telemetry/opentelemetry-dotnet/pull/4934 need improvement.
- Tests start a web application with socket hard coded to 5000. Test will fail if run in parallel, or another test isn't cleaned up properly, or the machine already has a site running on port 5000
- Tests use Task.Delay to wait for metric result. This slows down test execution and is potentially flaky.
What is the expected behavior?
- Test website uses
TestServerand runs in memory. - Test awaits the metric result to be available. This can be done easily with
MetricCollectorwhich has aWaitForMeasurementsAsyncmethod.
What is the actual behavior?
See symptom.
Reproduce
n/a
Additional Context
Add any other context about the problem here.
There is documentation here for how to test ASP.NET Core metrics in a correct, stable and efficent manner.
Here is another example of testing with TestServer and MetricCollector: https://github.com/dotnet/aspnetcore/blob/334676042dd1b78bad80bf73b5ad2b6133a9519d/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs#L915-L967
This issue was marked stale due to lack of activity and will be closed in 7 days. Commenting will instruct the bot to automatically remove the label. This bot runs once per day.
Closed as inactive. Feel free to reopen if this issue is still a concern.