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

[Extensions.Hosting.Tests] Nullable #5862

Merged
merged 10 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 17 additions & 13 deletions test/OpenTelemetry.Tests/Metrics/AggregatorTestsBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#nullable enable

using System.Diagnostics.Metrics;
using Xunit;

Expand Down Expand Up @@ -193,11 +195,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 +241,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 +339,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 +444,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 +464,10 @@ 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;
var mreToEnsureAllThreadsStart = args!.MreToEnsureAllThreadsStart;

if (Interlocked.Increment(ref args.ThreadStartedCount) == 3)
{
Expand All @@ -487,10 +485,10 @@ 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;
var mreToEnsureAllThreadsStart = args!.MreToEnsureAllThreadsStart;

if (Interlocked.Increment(ref args.ThreadStartedCount) == 3)
{
Expand All @@ -509,11 +507,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
Loading