Skip to content

Commit 8f70e15

Browse files
The test now locks the backend metrics mutex before reading error and success counts to avoid data races in tests.
PiperOrigin-RevId: 891969426
1 parent 9dbf105 commit 8f70e15

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

galog_syslog_linux_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,18 @@ func TestSyslog(t *testing.T) {
7777
time.Sleep(time.Millisecond)
7878
}
7979

80-
if be.metrics.errors != 0 {
81-
t.Errorf("got errors %d, want 0. Errors: \n%s\n", be.metrics.errors, strings.Join(be.metrics.errorMsgs, "\n"))
80+
be.metrics.mu.Lock()
81+
errors := be.metrics.errors
82+
errorMsgs := be.metrics.errorMsgs
83+
successMetric := be.metrics.success
84+
be.metrics.mu.Unlock()
85+
86+
if errors != 0 {
87+
t.Errorf("got errors %d, want 0. Errors: \n%s\n", errors, strings.Join(errorMsgs, "\n"))
8288
}
8389

8490
if !success {
85-
t.Errorf("got success %d, want %d", be.metrics.success, writtenEntries+1)
91+
t.Errorf("got success %d, want %d", successMetric, writtenEntries+1)
8692
}
8793
})
8894
}

0 commit comments

Comments
 (0)