opentelemetry-dotnet icon indicating copy to clipboard operation
opentelemetry-dotnet copied to clipboard

Improve .NET 8 metrics tests

Open JamesNK opened this issue 2 years ago • 3 comments

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 TestServer and runs in memory.
  • Test awaits the metric result to be available. This can be done easily with MetricCollector which has a WaitForMeasurementsAsync method.

What is the actual behavior?

See symptom.

Reproduce

n/a

Additional Context

Add any other context about the problem here.

JamesNK avatar Oct 21 '23 04:10 JamesNK

There is documentation here for how to test ASP.NET Core metrics in a correct, stable and efficent manner.

JamesNK avatar Oct 21 '23 04:10 JamesNK

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

JamesNK avatar Oct 21 '23 04:10 JamesNK

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.

github-actions[bot] avatar Oct 15 '24 03:10 github-actions[bot]

Closed as inactive. Feel free to reopen if this issue is still a concern.

github-actions[bot] avatar Oct 23 '24 03:10 github-actions[bot]