Skip to content

Commit

Permalink
Cleanup W3CTraceContextTests (#5858)
Browse files Browse the repository at this point in the history
Co-authored-by: Mikel Blanchard <mblanchard@macrosssoftware.com>
  • Loading branch information
Kielek and CodeBlanch authored Sep 24, 2024
1 parent 12a8ab0 commit 3a09a91
Showing 1 changed file with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class W3CTraceContextTests : IDisposable
To run the tests, invoke docker-compose.yml from the root of the repo:
opentelemetry>docker compose --file=test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/docker-compose.yml --project-directory=. up --exit-code-from=tests --build
*/
private const string W3cTraceContextEnvVarName = "OTEL_W3CTRACECONTEXT";
private static readonly Version? AspNetCoreHostingVersion = typeof(Microsoft.AspNetCore.Hosting.Builder.IApplicationBuilderFactory).Assembly.GetName().Version;
private const string W3CTraceContextEnvVarName = "OTEL_W3CTRACECONTEXT";
private readonly HttpClient httpClient = new();
private readonly ITestOutputHelper output;

Expand All @@ -31,13 +30,13 @@ public W3CTraceContextTests(ITestOutputHelper output)
}

[Trait("CategoryName", "W3CTraceContextTests")]
[SkipUnlessEnvVarFoundTheory(W3cTraceContextEnvVarName)]
[SkipUnlessEnvVarFoundTheory(W3CTraceContextEnvVarName)]
[InlineData("placeholder")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters", Justification = "Need to use SkipUnlessEnvVarFoundTheory")]
public void W3CTraceContextTestSuiteAsync(string value)
{
// configure SDK
using var tracerprovider = Sdk.CreateTracerProviderBuilder()
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAspNetCoreInstrumentation()
.Build();

Expand All @@ -51,13 +50,11 @@ public void W3CTraceContextTestSuiteAsync(string value)
{
foreach (var argument in data)
{
using var request = new HttpRequestMessage(HttpMethod.Post, argument.Url)
{
Content = new StringContent(
JsonSerializer.Serialize(argument.Arguments),
Encoding.UTF8,
"application/json"),
};
using var request = new HttpRequestMessage(HttpMethod.Post, argument.Url);
request.Content = new StringContent(
JsonSerializer.Serialize(argument.Arguments),
Encoding.UTF8,
"application/json");
await this.httpClient.SendAsync(request);
}
}
Expand All @@ -79,19 +76,7 @@ public void W3CTraceContextTestSuiteAsync(string value)
this.output.WriteLine("result:" + result);

// Assert on the last line

// TODO: Investigate failures on .NET6 vs .NET7. To see the details
// run the tests with console logger (done automatically by the CI
// jobs).

if (AspNetCoreHostingVersion!.Major <= 6)
{
Assert.StartsWith("FAILED (failures=3)", lastLine);
}
else
{
Assert.StartsWith("OK", lastLine);
}
Assert.StartsWith("OK", lastLine);
}

public void Dispose()
Expand Down

0 comments on commit 3a09a91

Please sign in to comment.