Skip to content

Commit c7b784e

Browse files
committed
[FAB-12217] fix data race in kafka logger test
Instead of adding serialization to the logger, use the serialized method in flogging to change the backend writer. It's simpler and safe for concurrency in the test. Change-Id: Ife516ada57e3286a61f539bcc6ffcd285e39f65e Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 674bb56 commit c7b784e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

orderer/consensus/kafka/logger_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ package kafka
88

99
import (
1010
"fmt"
11+
"os"
1112
"testing"
1213
"time"
1314

1415
"github.com/Shopify/sarama"
15-
"github.com/hyperledger/fabric/common/flogging/floggingtest"
16+
"github.com/hyperledger/fabric/common/flogging"
17+
"github.com/onsi/gomega/gbytes"
1618
"github.com/stretchr/testify/assert"
1719
)
1820

@@ -137,11 +139,9 @@ func TestLogPossibleKafkaVersionMismatch(t *testing.T) {
137139
topic := channelNameForTest(t)
138140
partition := int32(0)
139141

140-
oldLogger := logger
141-
defer func() { logger = oldLogger }()
142-
143-
l, recorder := floggingtest.NewTestLogger(t)
144-
logger = l
142+
buf := gbytes.NewBuffer()
143+
flogging.Global.SetWriter(buf)
144+
defer flogging.Global.SetWriter(os.Stderr)
145145

146146
broker := sarama.NewMockBroker(t, 500)
147147
defer broker.Close()
@@ -180,7 +180,7 @@ func TestLogPossibleKafkaVersionMismatch(t *testing.T) {
180180
case <-partitionConsumer.Messages():
181181
t.Fatalf("did not expect to receive message")
182182
case <-time.After(shortTimeout):
183-
entries := recorder.MessagesContaining("Kafka.Version specified in the orderer configuration is incorrectly set")
184-
assert.NotEmpty(t, entries)
183+
t.Logf("buffer:\n%s", buf.Contents())
184+
assert.Contains(t, string(buf.Contents()), "Kafka.Version specified in the orderer configuration is incorrectly set")
185185
}
186186
}

0 commit comments

Comments
 (0)