Skip to content

Commit ed81f62

Browse files
Fix data race in Linux compress maintainer tests
TestCompressMaintainOwner and TestCompressMaintainMode waited for the background compression goroutine with a fixed sleep before reading state it writes (the fakeFS owner map and the compressed file). The sleep established no happens-before relationship, so the race detector reported a data race on Linux, where these tests run. Replace the sleep with l.Close(), which now flushes the pending compression and joins the mill goroutine, synchronizing its writes with the subsequent assertions. This also makes the tests deterministic rather than relying on a timing window. Signed-off-by: Antonin Bas <antonin.bas@broadcom.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent bdc5dcc commit ed81f62

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

linux_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88
"syscall"
99
"testing"
10-
"time"
1110
)
1211

1312
func TestMaintainMode(t *testing.T) {
@@ -115,9 +114,10 @@ func TestCompressMaintainMode(t *testing.T) {
115114
err = l.Rotate()
116115
isNil(err, t)
117116

118-
// we need to wait a little bit since the files get compressed on a different
119-
// goroutine.
120-
<-time.After(10 * time.Millisecond)
117+
// Closing flushes the pending compression and waits for the mill
118+
// goroutine to exit, which also synchronizes its writes with the
119+
// assertions below.
120+
isNil(l.Close(), t)
121121

122122
// a compressed version of the log file should now exist with the correct
123123
// mode.
@@ -165,9 +165,10 @@ func TestCompressMaintainOwner(t *testing.T) {
165165
err = l.Rotate()
166166
isNil(err, t)
167167

168-
// we need to wait a little bit since the files get compressed on a different
169-
// goroutine.
170-
<-time.After(10 * time.Millisecond)
168+
// Closing flushes the pending compression and waits for the mill
169+
// goroutine to exit, which also synchronizes its writes to fakeFS with
170+
// the assertions below.
171+
isNil(l.Close(), t)
171172

172173
// a compressed version of the log file should now exist with the correct
173174
// owner.

0 commit comments

Comments
 (0)