Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use test host in unit tests #5040

Merged
merged 41 commits into from
Nov 22, 2023

Conversation

ngruson
Copy link
Contributor

@ngruson ngruson commented Nov 10, 2023

Fixes issue #4976

Changes

@JamesNK gave some recommendations about the usage of WebApplicationFactory.
As much as possible, we have implemented that.

Some test cases require a KestrelServer implementation for Kestrel metrics to be emitted.
In those cases, a WebApplication instance is instantiated to run the unit test against.
Previously, the hardcoded port number 5000 was used to run the host.
The port number is now made variable to isolate the unit test as much as possible.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@ngruson ngruson requested a review from a team November 10, 2023 15:25
Copy link

linux-foundation-easycla bot commented Nov 10, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@vishweshbankwar
Copy link
Member

@ngruson - Thank you for taking this. I have not used MetricCollector before. But looking at the link shared in #4976, I think it may not be something we can use for testing our scenario.

MetricCollector is testing metrics outside of OTel context by enabling its own MeterListener. In our case we want to validate if the user configures OTel SDK and instrumentation as shown below, will they get the desired metrics on .net8.0 exported?

Sdk.CreateMeterProviderBuilder()
   .AddAspNetCoreInstrumentation() 
   .Build();

In your test assert on collector is independent of assert on exported Items

cc: @JamesNK

@vishweshbankwar
Copy link
Member

regarding : https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs: We should delete this file as the test was added just for e.g. purpose. You could send a separate PR to remove that one.

@ngruson ngruson mentioned this pull request Nov 10, 2023
4 tasks
@ngruson
Copy link
Contributor Author

ngruson commented Nov 10, 2023

Other files that could be refactored to use the test host:

@vishweshbankwar
Copy link
Member

vishweshbankwar commented Nov 10, 2023

Other files that could be refactored to use the test host:

@ngruson Yes, it would be great if you could do that refactor. We don't need to refactor the Benchmarks one for now. BasicTests already uses WebApplicationFactory in most of the tests, we need to refactor the ones not using it like this one

W3CTraceContextTests.cs (don't know if this can be done in similar fashion. The endpoint is passed to a Python script.)

It should be possible. May be try that in separate PR than BasicTests.cs one?

@ngruson
Copy link
Contributor Author

ngruson commented Nov 18, 2023

@vishweshbankwar :
I resolved some merge conflicts and now the builds are passing.
Can you see if this is ok?

Copy link
Member

@vishweshbankwar vishweshbankwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: Thanks @ngruson! Please clean up the PR description as well and describe the actual changes.

@ngruson
Copy link
Contributor Author

ngruson commented Nov 22, 2023

LGTM: Thanks @ngruson! Please clean up the PR description as well and describe the actual changes.

Just updated the PR description, is it sufficient?
You probably don't update the change log for this?

@vishweshbankwar
Copy link
Member

LGTM: Thanks @ngruson! Please clean up the PR description as well and describe the actual changes.

Just updated the PR description, is it sufficient? You probably don't update the change log for this?

Correct, changelog updates are not done for unit test changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants