Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Fix data race on windowseventlogreceiver tests #36406

Merged
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
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
Loading