Skip to content

Commit

Permalink
[Extensions.Hosting.Tests] Nullable (#5862)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Kiełkowicz <[email protected]>
Co-authored-by: Mikel Blanchard <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent f502355 commit 19e1663
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<PropertyGroup>
<Description>Unit test project for OpenTelemetry .NET Core hosting library</Description>
<TargetFrameworks>$(TargetFrameworksForTests)</TargetFrameworks>
<!-- this is temporary. will remove in future PR. -->
<Nullable>disable</Nullable>
<DefineConstants>$(DefineConstants);BUILDING_HOSTING_TESTS</DefineConstants>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task AddOpenTelemetry_WithTracing_HostConfigurationHonoredTest()
var builder = new HostBuilder()
.ConfigureAppConfiguration(builder =>
{
builder.AddInMemoryCollection(new Dictionary<string, string>
builder.AddInMemoryCollection(new Dictionary<string, string?>
{
["TEST_KEY"] = "TEST_KEY_VALUE",
});
Expand All @@ -147,7 +147,7 @@ public async Task AddOpenTelemetry_WithTracing_HostConfigurationHonoredTest()

var configuration = sp.GetRequiredService<IConfiguration>();

var testKeyValue = configuration.GetValue<string>("TEST_KEY", null);
var testKeyValue = configuration.GetValue<string?>("TEST_KEY", null);

Assert.Equal("TEST_KEY_VALUE", testKeyValue);
});
Expand Down Expand Up @@ -252,7 +252,7 @@ public async Task AddOpenTelemetry_WithMetrics_HostConfigurationHonoredTest()
var builder = new HostBuilder()
.ConfigureAppConfiguration(builder =>
{
builder.AddInMemoryCollection(new Dictionary<string, string>
builder.AddInMemoryCollection(new Dictionary<string, string?>
{
["TEST_KEY"] = "TEST_KEY_VALUE",
});
Expand All @@ -270,7 +270,7 @@ public async Task AddOpenTelemetry_WithMetrics_HostConfigurationHonoredTest()

var configuration = sp.GetRequiredService<IConfiguration>();

var testKeyValue = configuration.GetValue<string>("TEST_KEY", null);
var testKeyValue = configuration.GetValue<string?>("TEST_KEY", null);

Assert.Equal("TEST_KEY_VALUE", testKeyValue);
});
Expand Down Expand Up @@ -375,7 +375,7 @@ public void AddOpenTelemetry_WithLogging_HostConfigurationHonoredTest()
var builder = new HostBuilder()
.ConfigureAppConfiguration(builder =>
{
builder.AddInMemoryCollection(new Dictionary<string, string>
builder.AddInMemoryCollection(new Dictionary<string, string?>
{
["TEST_KEY"] = "TEST_KEY_VALUE",
});
Expand All @@ -393,7 +393,7 @@ public void AddOpenTelemetry_WithLogging_HostConfigurationHonoredTest()

var configuration = sp.GetRequiredService<IConfiguration>();

var testKeyValue = configuration.GetValue<string>("TEST_KEY", null);
var testKeyValue = configuration.GetValue<string?>("TEST_KEY", null);

Assert.Equal("TEST_KEY_VALUE", testKeyValue);
});
Expand Down
33 changes: 20 additions & 13 deletions test/OpenTelemetry.Tests/Metrics/AggregatorTestsBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#nullable enable

using System.Diagnostics;
using System.Diagnostics.Metrics;
using Xunit;

Expand Down Expand Up @@ -193,11 +196,7 @@ public void MultiThreadedHistogramUpdateAndSnapShotTest()
{
var boundaries = Array.Empty<double>();
var histogramPoint = new MetricPoint(this.aggregatorStore, AggregationType.Histogram, null, boundaries, Metric.DefaultExponentialHistogramMaxBuckets, Metric.DefaultExponentialHistogramMaxScale);
var argsToThread = new ThreadArguments
{
HistogramPoint = histogramPoint,
MreToEnsureAllThreadsStart = new ManualResetEvent(false),
};
var argsToThread = new ThreadArguments(histogramPoint, new ManualResetEvent(false));

var numberOfThreads = 2;
var snapshotThread = new Thread(HistogramSnapshotThread);
Expand Down Expand Up @@ -243,7 +242,7 @@ public void MultiThreadedHistogramUpdateAndSnapShotTest()
[InlineData("System.Net.Http", "http.client.request.time_in_queue", "s", KnownHistogramBuckets.DefaultShortSeconds)]
[InlineData("System.Net.NameResolution", "dns.lookup.duration", "s", KnownHistogramBuckets.DefaultShortSeconds)]
[InlineData("General.App", "simple.alternative.counter", "s", KnownHistogramBuckets.Default)]
public void HistogramBucketsDefaultUpdatesForSecondsTest(string meterName, string instrumentName, string unit, KnownHistogramBuckets expectedHistogramBuckets)
public void HistogramBucketsDefaultUpdatesForSecondsTest(string meterName, string instrumentName, string? unit, KnownHistogramBuckets expectedHistogramBuckets)
{
using var meter = new Meter(meterName);

Expand Down Expand Up @@ -341,7 +340,7 @@ internal void ExponentialHistogramTests(AggregationType aggregationType, Aggrega

foreach (var value in valuesToRecord)
{
aggregatorStore.Update(value, Array.Empty<KeyValuePair<string, object>>());
aggregatorStore.Update(value, Array.Empty<KeyValuePair<string, object?>>());

if (value >= 0)
{
Expand Down Expand Up @@ -446,7 +445,7 @@ internal void ExponentialMaxScaleConfigWorks(int? maxScale)
this.emitOverflowAttribute,
this.shouldReclaimUnusedMetricPoints);

aggregatorStore.Update(10, Array.Empty<KeyValuePair<string, object>>());
aggregatorStore.Update(10, Array.Empty<KeyValuePair<string, object?>>());

aggregatorStore.Snapshot();

Expand All @@ -466,10 +465,11 @@ internal void ExponentialMaxScaleConfigWorks(int? maxScale)
Assert.Equal(expectedScale, metricPoint.GetExponentialHistogramData().Scale);
}

private static void HistogramSnapshotThread(object obj)
private static void HistogramSnapshotThread(object? obj)
{
var args = obj as ThreadArguments;
var mreToEnsureAllThreadsStart = args.MreToEnsureAllThreadsStart;
Debug.Assert(args != null, "args was null");
var mreToEnsureAllThreadsStart = args!.MreToEnsureAllThreadsStart;

if (Interlocked.Increment(ref args.ThreadStartedCount) == 3)
{
Expand All @@ -487,10 +487,11 @@ private static void HistogramSnapshotThread(object obj)
}
}

private static void HistogramUpdateThread(object obj)
private static void HistogramUpdateThread(object? obj)
{
var args = obj as ThreadArguments;
var mreToEnsureAllThreadsStart = args.MreToEnsureAllThreadsStart;
Debug.Assert(args != null, "args was null");
var mreToEnsureAllThreadsStart = args!.MreToEnsureAllThreadsStart;

if (Interlocked.Increment(ref args.ThreadStartedCount) == 3)
{
Expand All @@ -509,11 +510,17 @@ private static void HistogramUpdateThread(object obj)

private class ThreadArguments
{
public readonly ManualResetEvent MreToEnsureAllThreadsStart;
public MetricPoint HistogramPoint;
public ManualResetEvent MreToEnsureAllThreadsStart;
public int ThreadStartedCount;
public long ThreadsFinishedAllUpdatesCount;
public double SumOfDelta;

public ThreadArguments(MetricPoint histogramPoint, ManualResetEvent mreToEnsureAllThreadsStart)
{
this.HistogramPoint = histogramPoint;
this.MreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart;
}
}
}

Expand Down
Loading

0 comments on commit 19e1663

Please sign in to comment.