Skip to content

Commit fdf47c6

Browse files
committed
fix(test): remove testLogger from TrackLeader test
As it turns out, this setup was periodically causing the test to fail due to a data race occurring on the `Logger` global when the defer ran (!) Fixes #2011
1 parent 52ac254 commit fdf47c6

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

consumer_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,6 @@ func TestConsumeMessagesFromReadReplicaErrorUnknown(t *testing.T) {
900900
//
901901
// See https://github.com/Shopify/sarama/issues/1927
902902
func TestConsumeMessagesTrackLeader(t *testing.T) {
903-
prevLogger := Logger
904-
defer func() { Logger = prevLogger }()
905-
Logger = &testLogger{t}
906-
907903
cfg := NewConfig()
908904
cfg.ClientID = t.Name()
909905
cfg.Metadata.RefreshFrequency = time.Millisecond * 50

logger_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@ import "testing"
66
// logs of the given T passed from Test functions.
77
// and records the text in the error log.
88
//
9-
9+
// nolint:unused
1010
type testLogger struct {
1111
t *testing.T
1212
}
1313

14+
// nolint:unused
1415
func (l *testLogger) Print(v ...interface{}) {
1516
if l.t != nil {
1617
l.t.Helper()
1718
l.t.Log(v...)
1819
}
1920
}
2021

22+
// nolint:unused
2123
func (l *testLogger) Printf(format string, v ...interface{}) {
2224
if l.t != nil {
2325
l.t.Helper()
2426
l.t.Logf(format, v...)
2527
}
2628
}
2729

30+
// nolint:unused
2831
func (l *testLogger) Println(v ...interface{}) {
2932
if l.t != nil {
3033
l.t.Helper()

0 commit comments

Comments
 (0)