Skip to content

Commit

Permalink
Test fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Jan 24, 2025
1 parent f21d622 commit 8f1cc0d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public sealed class ZipkinExporterTests : IDisposable
private static readonly ConcurrentDictionary<Guid, string> Responses = new();

private readonly IDisposable testServer;
private readonly ActivityListener activityListener;
private readonly string testServerHost;
private readonly int testServerPort;

Expand All @@ -42,16 +41,6 @@ public ZipkinExporterTests()
out this.testServerHost,
out this.testServerPort);

this.activityListener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => options.Parent.TraceFlags.HasFlag(ActivityTraceFlags.Recorded)
? ActivitySamplingResult.AllDataAndRecorded
: ActivitySamplingResult.AllData,
};

ActivitySource.AddActivityListener(this.activityListener);

static void ProcessServerRequest(HttpListenerContext context)
{
context.Response.StatusCode = 200;
Expand All @@ -71,7 +60,6 @@ static void ProcessServerRequest(HttpListenerContext context)
public void Dispose()
{
this.testServer.Dispose();
this.activityListener.Dispose();
}

[Fact]
Expand Down Expand Up @@ -458,6 +446,16 @@ internal static Activity CreateTestActivity(
string? statusDescription = null,
DateTime? dateTime = null)
{
using var activityListener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => options.Parent.TraceFlags.HasFlag(ActivityTraceFlags.Recorded)
? ActivitySamplingResult.AllDataAndRecorded
: ActivitySamplingResult.AllData,
};

ActivitySource.AddActivityListener(activityListener);

var startTimestamp = DateTime.UtcNow;
var endTimestamp = startTimestamp.AddSeconds(60);
var eventTimestamp = DateTime.UtcNow;
Expand Down Expand Up @@ -535,6 +533,8 @@ internal static Activity CreateTestActivity(
links,
startTime: startTimestamp)!;

Assert.NotNull(activity);

if (addEvents)
{
foreach (var evnt in events)
Expand Down

0 comments on commit 8f1cc0d

Please sign in to comment.