Skip to content

Commit

Permalink
Nullable OpenTelemetry.Instrumentation.EventCounters.Tests (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Sep 19, 2023
1 parent 48a1b38 commit 7b68f6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void EventCounter()
options.AddEventSources(source.Name);
})
.AddInMemoryExporter(metricItems)
.Build();
.Build()!;

// Act
counter.WriteMetric(1997.0202);
Expand All @@ -67,7 +67,7 @@ public void IncrementingEventCounter()
options.AddEventSources(source.Name);
})
.AddInMemoryExporter(metricItems)
.Build();
.Build()!;

// Act
incCounter.Increment(1);
Expand Down Expand Up @@ -96,7 +96,7 @@ public void PollingCounter()
options.AddEventSources(source.Name);
})
.AddInMemoryExporter(metricItems)
.Build();
.Build()!;

// Act
var metric = AwaitExport(meterProvider, metricItems, expectedInstrumentName: "ec.c.poll-c");
Expand All @@ -122,7 +122,7 @@ public void IncrementingPollingCounter()
options.AddEventSources(source.Name);
})
.AddInMemoryExporter(metricItems)
.Build();
.Build()!;

// Act
var metric = AwaitExport(meterProvider, metricItems, expectedInstrumentName: "ec.d.inc-poll-c");
Expand All @@ -133,13 +133,6 @@ public void IncrementingPollingCounter()
Assert.Equal(1, GetActualValue(metric));
}

[Fact]
public void ThrowExceptionWhenBuilderIsNull()
{
MeterProviderBuilder builder = null;
Assert.Throws<ArgumentNullException>(() => builder.AddEventCountersInstrumentation());
}

[Fact]
public void ThrowExceptionForUnsupportedEventSources()
{
Expand Down Expand Up @@ -177,7 +170,7 @@ public void EventSourceNameShortening(string sourceName, string eventName, strin
options.AddEventSources(source.Name);
})
.AddInMemoryExporter(metricItems)
.Build();
.Build()!;

// Act
connections.Increment(1);
Expand Down Expand Up @@ -235,16 +228,16 @@ private static double GetActualValue(Metric metric)
return sum;
}

private static Metric AwaitExport(MeterProvider meterProvider, List<Metric> exportedItems, string expectedInstrumentName)
private static Metric? AwaitExport(MeterProvider meterProvider, List<Metric> exportedItems, string expectedInstrumentName)
{
Metric metric = null;
Metric? metric = null;

SpinWait.SpinUntil(
() =>
{
Thread.Sleep(100);
meterProvider.ForceFlush();
metric = exportedItems.Where(x => x.Name == expectedInstrumentName).FirstOrDefault();
metric = exportedItems.FirstOrDefault(x => x.Name == expectedInstrumentName);
return metric != null;
},
10_000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<IncludeSharedTestSource>true</IncludeSharedTestSource>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 7b68f6e

Please sign in to comment.