Skip to content

Commit 0c26ce2

Browse files
SimonCropprajkumar-rangaraj
andauthoredFeb 6, 2025··
remove redundant isDisposing pattern in StressTest (#6082)
Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
1 parent c99f9a1 commit 0c26ce2

File tree

4 files changed

+16
-37
lines changed

4 files changed

+16
-37
lines changed
 

‎test/OpenTelemetry.Tests.Stress.Logs/Program.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public LogsStressTest(StressTestOptions options)
3232
this.logger = this.loggerFactory.CreateLogger<LogsStressTest>();
3333
}
3434

35+
public override void Dispose()
36+
{
37+
this.loggerFactory.Dispose();
38+
base.Dispose();
39+
}
40+
3541
protected override void RunWorkItemInParallel()
3642
{
3743
this.logger.FoodRecallNotice(
@@ -41,15 +47,5 @@ protected override void RunWorkItemInParallel()
4147
recallReasonDescription: "due to a possible health risk from Listeria monocytogenes",
4248
companyName: "Contoso Fresh Vegetables, Inc.");
4349
}
44-
45-
protected override void Dispose(bool isDisposing)
46-
{
47-
if (isDisposing)
48-
{
49-
this.loggerFactory.Dispose();
50-
}
51-
52-
base.Dispose(isDisposing);
53-
}
5450
}
5551
}

‎test/OpenTelemetry.Tests.Stress.Metrics/Program.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public MetricsStressTest(MetricsStressTestOptions options)
7777
this.meterProvider = builder.Build();
7878
}
7979

80+
public override void Dispose()
81+
{
82+
this.meterProvider.Dispose();
83+
base.Dispose();
84+
}
85+
8086
protected override void WriteRunInformationToConsole()
8187
{
8288
if (this.Options.PrometheusTestMetricsPort != 0)
@@ -105,16 +111,6 @@ protected override void RunWorkItemInParallel()
105111
new("DimName3", DimensionValues[random.Next(0, ArraySize)]));
106112
}
107113
}
108-
109-
protected override void Dispose(bool isDisposing)
110-
{
111-
if (isDisposing)
112-
{
113-
this.meterProvider.Dispose();
114-
}
115-
116-
base.Dispose(isDisposing);
117-
}
118114
}
119115

120116
private sealed class MetricsStressTestOptions : StressTestOptions

‎test/OpenTelemetry.Tests.Stress.Traces/Program.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@ public TracesStressTest(StressTestOptions options)
2626
.Build();
2727
}
2828

29+
public override void Dispose() =>
30+
this.tracerProvider.Dispose();
31+
2932
protected override void RunWorkItemInParallel()
3033
{
3134
using var activity = ActivitySource.StartActivity("test");
3235

3336
activity?.SetTag("foo", "value");
3437
}
35-
36-
protected override void Dispose(bool isDisposing)
37-
{
38-
if (isDisposing)
39-
{
40-
this.tracerProvider.Dispose();
41-
}
42-
43-
base.Dispose(isDisposing);
44-
}
4538
}
4639
}

‎test/OpenTelemetry.Tests.Stress/StressTest.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ protected StressTest(T options)
2222

2323
public T Options { get; }
2424

25-
public void Dispose()
25+
public virtual void Dispose()
2626
{
27-
this.Dispose(true);
28-
GC.SuppressFinalize(this);
2927
}
3028

3129
public void RunSynchronously()
@@ -203,10 +201,6 @@ protected virtual void WriteRunInformationToConsole()
203201

204202
protected abstract void RunWorkItemInParallel();
205203

206-
protected virtual void Dispose(bool isDisposing)
207-
{
208-
}
209-
210204
// Padding to avoid false sharing.
211205
// For most systems, the cache line size should be less than or equal to 128 bytes.
212206
private struct MeasurementData

0 commit comments

Comments
 (0)
Please sign in to comment.