Skip to content

Commit

Permalink
[chore] Fix data race on windowseventlogreceiver tests (open-telemetr…
Browse files Browse the repository at this point in the history
…y#36406)

Fixes a data race detected
[here](open-telemetry#34687 (comment)).
This doesn't solve the flakiness detected on this receiver tests, only
avoids the data race.
  • Loading branch information
pjanotti authored and RutvikS-crest committed Dec 9, 2024
1 parent 52f7f20 commit 0246948
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions receiver/windowseventlogreceiver/receiver_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,17 @@ func assertEventSourceInstallation(t *testing.T, src string) (uninstallEventSour
func assertExpectedLogRecords(t *testing.T, sink *consumertest.LogsSink, expectedEventSrc string, expectedEventCount int) []plog.LogRecord {
var actualLogRecords []plog.LogRecord

// logs sometimes take a while to be written, so a substantial wait buffer is needed
assert.EventuallyWithT(t, func(c *assert.CollectT) {
// We can't use assert.Eventually because the condition function is launched in a separate goroutine
// and we want to return the slice filled by the condition function. Use a local condition check
// to avoid data race conditions.
startTime := time.Now()
actualLogRecords = filterAllLogRecordsBySource(t, sink, expectedEventSrc)
for len(actualLogRecords) != expectedEventCount && time.Since(startTime) < 10*time.Second {
time.Sleep(250 * time.Millisecond)
actualLogRecords = filterAllLogRecordsBySource(t, sink, expectedEventSrc)
assert.Len(c, actualLogRecords, expectedEventCount)
}, 10*time.Second, 250*time.Millisecond)
}

require.Len(t, actualLogRecords, expectedEventCount)

return actualLogRecords
}
Expand Down

0 comments on commit 0246948

Please sign in to comment.