Skip to content

Commit

Permalink
fix: datarace in debug stifling logger test (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneutt authored Jul 9, 2021
1 parent 4125d78 commit f42f1c9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/util/debug_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,19 @@ func TestDebugLoggerThreadSafety(t *testing.T) {
log := MakeDebugLoggerWithReducedRedudancy(buf, &logrus.JSONFormatter{}, 0, time.Minute*30)

// spam the logger concurrently across several goroutines to ensure no dataraces
wg := &sync.WaitGroup{}
for i := 0; i < 100; i++ {
go func() { log.Debug("unique") }()
wg.Add(1)
go func() {
defer wg.Done()
log.Debug("unique")
}()
}
wg.Wait()
assert.Contains(t, buf.String(), "unique")
lines := strings.Split(buf.String(), "\n")
// Ensure that _some_ lines have been stifled. The actual number is not deterministic.
assert.True(t, len(lines) < 100)
}

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit f42f1c9

Please sign in to comment.