Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -24,7 +24,7 @@ public void PrivateInterfaceReverseProxyTest()
{
Type iLogEventEnricherType = typeof(Datadog.Trace.Vendors.Serilog.Core.ILogEventEnricher);

var resetEvent = new ManualResetEventSlim();
using var resetEvent = new ManualResetEventSlim();

var instance = new InternalLogEventEnricherImpl(resetEvent);

Expand All @@ -44,7 +44,7 @@ public void PrivateInterfaceReverseProxyTest()
[Fact]
public void PrivateAbstractClassReverseProxyTest()
{
var resetEvent = new ManualResetEventSlim();
using var resetEvent = new ManualResetEventSlim();

var eventInstance = new LogEventPropertyValueImpl(resetEvent);

Expand All @@ -62,7 +62,7 @@ public void PublicInterfaceReverseProxyTest()
{
Type iLogEventEnricherType = typeof(Serilog.Core.ILogEventEnricher);

var resetEvent = new ManualResetEventSlim();
using var resetEvent = new ManualResetEventSlim();

var instance = new PublicLogEventEnricherImpl(resetEvent);

Expand All @@ -81,7 +81,7 @@ public void PublicInterfaceReverseProxyTest()
[Fact]
public void PublicAbstractClassReverseProxyTest()
{
var resetEvent = new ManualResetEventSlim();
using var resetEvent = new ManualResetEventSlim();

var eventInstance = new LogEventPropertyValueImpl(resetEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task TryStartApp(TestHelper helper, bool? enableSecurity = null, st
WriteToOutput($"Starting aspnetcore sample, agentPort: {Agent.Port}");
Process = await helper.StartSample(Agent, arguments: null, packageVersion: packageVersion, aspNetCorePort: 0, enableSecurity: enableSecurity, externalRulesFile: externalRulesFile);

var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

int? port = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public void AgentWriterEnqueueFlushTasks()

private static bool WaitForDequeue(AgentWriter agent, bool wakeUpThread = true, int delay = -1)
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

agent.WriteWatermark(() => mutex.Set(), wakeUpThread);

Expand Down
24 changes: 12 additions & 12 deletions tracer/test/Datadog.Trace.Tests/Agent/DiscoveryServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DiscoveryServiceTests
[Fact]
public async Task HandlesFlakyConfiguration()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var factory = new TestRequestFactory(
x => new FaultyApiRequest(x),
x => new TestApiRequest(x));
Expand All @@ -48,7 +48,7 @@ public async Task ReturnsDeserializedConfig()
var clientDropP0s = true;
var version = "1.26.3";
var evpProxyEndpoint = "evp_proxy/v4";
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var factory = new TestRequestFactory(
x => new TestApiRequest(x, responseContent: GetConfig(clientDropP0s, version)));

Expand Down Expand Up @@ -78,7 +78,7 @@ public async Task ReturnsDeserializedConfig()
public async Task DoesNotFireInitialCallbackIfInitialConfigNotFetched()
{
var notificationFired = false;
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var factory = new TestRequestFactory(
x =>
{
Expand All @@ -100,7 +100,7 @@ public async Task DoesNotFireInitialCallbackIfInitialConfigNotFetched()
public async Task FiresInitialCallbackIfInitialConfigAlreadyFetched()
{
int notificationCount = 0;
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var factory = new TestRequestFactory(
x =>
{
Expand All @@ -123,8 +123,8 @@ public async Task FiresInitialCallbackIfInitialConfigAlreadyFetched()
public async Task DoesNotFireCallbackOnRecheckIfNoChangesToConfig()
{
int notificationCount = 0;
var mutex1 = new ManualResetEventSlim();
var mutex3 = new ManualResetEventSlim();
using var mutex1 = new ManualResetEventSlim();
using var mutex3 = new ManualResetEventSlim();
var recheckIntervalMs = 1_000; // ms
var factory = new TestRequestFactory(
x =>
Expand Down Expand Up @@ -155,8 +155,8 @@ public async Task DoesNotFireCallbackOnRecheckIfNoChangesToConfig()
public async Task FiresCallbackOnRecheckIfHasChangesToConfig()
{
var notificationCount = 0;
var mutex1 = new ManualResetEventSlim();
var mutex3 = new ManualResetEventSlim();
using var mutex1 = new ManualResetEventSlim();
using var mutex3 = new ManualResetEventSlim();
var recheckIntervalMs = 1_000; // ms
var factory = new TestRequestFactory(
x =>
Expand Down Expand Up @@ -187,8 +187,8 @@ public async Task FiresCallbackOnRecheckIfHasChangesToConfig()
public async Task DoesNotFireAfterUnsubscribing()
{
var notificationCount = 0;
var mutex1 = new ManualResetEventSlim();
var mutex3 = new ManualResetEventSlim();
using var mutex1 = new ManualResetEventSlim();
using var mutex3 = new ManualResetEventSlim();

var recheckIntervalMs = 1_000; // ms
var factory = new TestRequestFactory(
Expand Down Expand Up @@ -227,7 +227,7 @@ void Callback(AgentConfiguration x)
[Fact]
public async Task DisposesInATimelyManner()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

var factory = new TestRequestFactory(
x =>
Expand Down Expand Up @@ -310,7 +310,7 @@ public void AgentConfigurationComparesByValue()
[Flaky("This is an inherently flaky test as it relies on time periods")]
public async Task HandlesFailuresInApiWithBackoff()
{
var mutex = new ManualResetEventSlim(initialState: false, spinCount: 0);
using var mutex = new ManualResetEventSlim(initialState: false, spinCount: 0);
var factory = new TestRequestFactory(
_ => new ThrowingRequest(),
_ => new ThrowingRequest(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task CallFlushAutomatically()
const int bucketDurationSeconds = 1;
var bucketDuration = TimeSpan.FromSeconds(bucketDurationSeconds);

var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

int invocationCount = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DatadogSinkTests
[Fact]
public void SinkSendsMessagesToLogsApi()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

var logsApi = new TestLogsApi(_ =>
{
Expand All @@ -51,7 +51,7 @@ public void SinkSendsMessagesToLogsApi()
[Fact]
public void SinkRejectsGiantMessages()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

var logsApi = new TestLogsApi();
var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait);
Expand All @@ -74,7 +74,7 @@ public void SinkRejectsGiantMessages()
[Fact]
public void SinkSendsMessageAsJsonBatch()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
int logsReceived = 0;
const int expectedCount = 2;

Expand Down Expand Up @@ -117,7 +117,7 @@ bool LogsSentCallback(int x)
[Fact]
public void SinkSendsMultipleBatches()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
int logsReceived = 0;
const int expectedCount = 5;

Expand Down Expand Up @@ -160,7 +160,7 @@ bool LogsSentCallback(int x)
[InlineData(false)]
public async Task EmitBatchEchoesLogsApiReturnValue(bool logsApiResponse)
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
bool LogsSentCallback(int x)
{
mutex.Set();
Expand All @@ -184,7 +184,7 @@ bool LogsSentCallback(int x)
[Fact]
public void IfCircuitBreakerBreaksThenNoApiRequestsAreSent()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
int logsReceived = 0;

bool LogsSentCallback(int x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class OtlpSinkTests
[Fact]
public void SinkSendsLogsToOtlpExporter()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var capturedLogs = new List<LogPoint>();

var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait);
Expand All @@ -57,7 +57,7 @@ public void SinkSendsLogsToOtlpExporter()
[Fact]
public void SinkBatchesMultipleLogs()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var capturedLogs = new List<LogPoint>();
int batchCount = 0;

Expand Down Expand Up @@ -91,7 +91,7 @@ public void SinkBatchesMultipleLogs()
[Fact]
public void SinkIncludesTraceContextWhenAvailable()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var capturedLogs = new List<LogPoint>();

var options = new BatchingSinkOptions(batchSizeLimit: 1, queueLimit: DefaultQueueLimit, period: TinyWait);
Expand Down Expand Up @@ -120,7 +120,7 @@ public void SinkIncludesTraceContextWhenAvailable()
[Fact]
public void SinkIncludesAttributesInLogs()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var capturedLogs = new List<LogPoint>();

var options = new BatchingSinkOptions(batchSizeLimit: 1, queueLimit: DefaultQueueLimit, period: TinyWait);
Expand Down Expand Up @@ -156,7 +156,7 @@ public void SinkIncludesAttributesInLogs()
[Fact]
public void SinkIgnoresNonOtlpLogEvents()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var capturedLogs = new List<LogPoint>();

var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void SinkIgnoresNonOtlpLogEvents()
[Fact]
public void SinkHandlesAllLogLevels()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var capturedLogs = new List<LogPoint>();

var options = new BatchingSinkOptions(batchSizeLimit: 6, queueLimit: DefaultQueueLimit, period: TinyWait);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task AfterDisposed_AndAnEventIsQueued_ItIsNotWrittenToABatch()
[Fact]
public async Task AfterMultipleFailures_SinkIsPermanentlyDisabled()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var emitResults = Enumerable.Repeat(false, FailuresBeforeCircuitBreak);
var sink = new InMemoryBatchedSink(
DefaultBatchingOptions,
Expand Down Expand Up @@ -146,7 +146,7 @@ public async Task AfterInitialSuccessThenMultipleFailures_SinkIsTemporarilyDisab
// there's a short delay before the result is processed and logging is disabled. By
// hooking into the sink DelayEvents, we can make sure the result is processed _before_
// we add the next event
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
sink.DelayEventAction = x =>
{
_output.WriteLine($"Flushing delayed for {x} seconds");
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task ClosingAfterStart_PreventsEmitting_AndCantBeRestarted()
[Fact]
public void ClosingImmediatelyCallsDisableSinkAction()
{
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
var sink = new InMemoryBatchedSink(DefaultBatchingOptions, () => mutex.Set());
var evt = new TestEvent("Some event");
sink.EnqueueLog(evt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class RuntimeMetricsWriterTests
public void PushEvents()
{
var listener = new Mock<IRuntimeMetricsListener>();
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

listener.Setup(l => l.Refresh())
.Callback(() => mutex.Set());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public async Task AllMetricsAreReturned_ForCiVisibilityCollector(string wafVersi
public async Task ShouldAggregateMetricsAutomatically()
{
var aggregationPeriod = TimeSpan.FromMilliseconds(500);
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();

var collector = new MetricsTelemetryCollector(
aggregationPeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task TypicalLoop()

// we expect an infinite flush interval, because initialization is not complete
// we'll fast-forward to 5s for now
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
_delayFactory.Task = delay =>
{
delay.Should().Be(Timeout.InfiniteTimeSpan);
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task TypicalLoop_WithLogsQueueTrigger()

// we expect an infinite flush interval, because initialization is not complete
// we'll fast-forward to 5s for now
var delayMutex = new ManualResetEventSlim();
using var delayMutex = new ManualResetEventSlim();
_delayFactory.Task = delay =>
{
delay.Should().Be(Timeout.InfiniteTimeSpan);
Expand Down Expand Up @@ -231,7 +231,7 @@ public async Task CanChangeFlushInterval()
_scheduler.ShouldFlushTelemetry.Should().BeFalse();

// partial advancement
var mutex = new ManualResetEventSlim();
using var mutex = new ManualResetEventSlim();
_delayFactory.Task = delay =>
{
delay.Should().Be(Timeout.InfiniteTimeSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,23 @@ public ActionResult Sampling(bool parentTrace = true)
else
{
// Same test but without a parent automatic trace
var mutex = new ManualResetEventSlim();

ThreadPool.UnsafeQueueUserWorkItem(_ =>
using (var mutex = new ManualResetEventSlim())
{
try
{
CreateTraces();
}
finally
ThreadPool.UnsafeQueueUserWorkItem(_ =>
{
mutex.Set();
}
try
{
CreateTraces();
}
finally
{
mutex.Set();
}

}, null);
}, null);

mutex.Wait();
mutex.Wait();
}
}

return View();
Expand Down
Loading
Loading