From fdf47c676e0b989538b4b7a67d5f77095fa7b482 Mon Sep 17 00:00:00 2001 From: Dominic Evans Date: Tue, 14 Sep 2021 00:25:07 +0100 Subject: [PATCH] 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 --- consumer_test.go | 4 ---- logger_test.go | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/consumer_test.go b/consumer_test.go index 4d5ca7360..811fb9082 100644 --- a/consumer_test.go +++ b/consumer_test.go @@ -900,10 +900,6 @@ func TestConsumeMessagesFromReadReplicaErrorUnknown(t *testing.T) { // // See https://github.com/Shopify/sarama/issues/1927 func TestConsumeMessagesTrackLeader(t *testing.T) { - prevLogger := Logger - defer func() { Logger = prevLogger }() - Logger = &testLogger{t} - cfg := NewConfig() cfg.ClientID = t.Name() cfg.Metadata.RefreshFrequency = time.Millisecond * 50 diff --git a/logger_test.go b/logger_test.go index b15231188..1aa79c5ee 100644 --- a/logger_test.go +++ b/logger_test.go @@ -6,11 +6,12 @@ import "testing" // logs of the given T passed from Test functions. // and records the text in the error log. // - +// nolint:unused type testLogger struct { t *testing.T } +// nolint:unused func (l *testLogger) Print(v ...interface{}) { if l.t != nil { l.t.Helper() @@ -18,6 +19,7 @@ func (l *testLogger) Print(v ...interface{}) { } } +// nolint:unused func (l *testLogger) Printf(format string, v ...interface{}) { if l.t != nil { l.t.Helper() @@ -25,6 +27,7 @@ func (l *testLogger) Printf(format string, v ...interface{}) { } } +// nolint:unused func (l *testLogger) Println(v ...interface{}) { if l.t != nil { l.t.Helper()