Skip to content

Commit

Permalink
[chore] Fix data race on windowseventlogreceiver tests (#36406)
Browse files Browse the repository at this point in the history
Fixes a data race detected
[here](#34687 (comment)).
This doesn't solve the flakiness detected on this receiver tests, only
avoids the data race.
  • Loading branch information
pjanotti authored Nov 18, 2024
1 parent ec784fb commit bf5cd1c
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 bf5cd1c

Please sign in to comment.