Skip to content

Commit

Permalink
Fix race condition in TelemetryControllerSchedulerTests (#6514)
Browse files Browse the repository at this point in the history
## Summary of changes

Fix a race condition in
`TelemetryControllerSchedulerTests.TypicalLoop_WithLogsQueueTrigger`.

## Reason for change

Flaky test.

## Implementation details

In one case, the task returned by `_scheduler.WaitForNextInterval()`
wasn't awaited, which caused the assertion to be evaluated too soon.
  • Loading branch information
kevingosse authored Jan 9, 2025
1 parent 7c9ef26 commit 48b0333
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="TelemetryControllerSchedulerTests.cs" company="Datadog">
// <copyright file="TelemetryControllerSchedulerTests.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
Expand Down Expand Up @@ -162,6 +162,8 @@ public async Task TypicalLoop_WithLogsQueueTrigger()
delayMutex.Wait();
queueTcs.SetResult(true); // this triggers the queue task

await waitTask;

// t = 15s;
_scheduler.ShouldFlushTelemetry.Should().BeFalse(); // not a complete interval
_scheduler.ShouldFlushRedactedErrorLogs.Should().BeTrue(); // triggered by queue
Expand All @@ -180,7 +182,7 @@ public async Task TypicalLoop_WithLogsQueueTrigger()
// t = 125s;
_scheduler.ShouldFlushTelemetry.Should().BeTrue();
_scheduler.ShouldFlushRedactedErrorLogs.Should().BeTrue();
}
}

[Fact]
public async Task DoesNotFlushTelemetryUntilInitialized()
Expand Down

0 comments on commit 48b0333

Please sign in to comment.