Skip to content

Commit

Permalink
ingest storage: synchronize logger access between parallel tests (#9428)
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dimitrov <[email protected]>
  • Loading branch information
dimitarvdimitrov authored Sep 28, 2024
1 parent 1bf2077 commit 978c109
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/storage/ingest/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1827,10 +1827,12 @@ func withLogger(logger log.Logger) func(cfg *readerTestCfg) {
}
}

var testingLogger = mimirtest.NewTestingLogger(nil)

func defaultReaderTestConfig(t *testing.T, addr string, topicName string, partitionID int32, consumer recordConsumer) *readerTestCfg {
return &readerTestCfg{
registry: prometheus.NewPedanticRegistry(),
logger: mimirtest.NewTestingLogger(t),
logger: testingLogger.WithT(t),
kafka: createTestKafkaConfig(addr, topicName),
partitionID: partitionID,
consumer: consumer,
Expand Down
21 changes: 15 additions & 6 deletions pkg/util/test/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ import (
"github.com/go-kit/log"
)

type testingLogger struct {
type TestingLogger struct {
t testing.TB
mtx sync.Mutex
mtx *sync.Mutex
}

func NewTestingLogger(t testing.TB) log.Logger {
return &testingLogger{
t: t,
func NewTestingLogger(t testing.TB) *TestingLogger {
return &TestingLogger{
t: t,
mtx: &sync.Mutex{},
}
}

func (l *testingLogger) Log(keyvals ...interface{}) error {
// WithT returns a new logger that logs to t. Writes between the new logger and the original logger are synchronized.
func (l *TestingLogger) WithT(t testing.TB) log.Logger {
return &TestingLogger{
t: t,
mtx: l.mtx,
}
}

func (l *TestingLogger) Log(keyvals ...interface{}) error {
// Prepend log with timestamp.
keyvals = append([]interface{}{time.Now().String()}, keyvals...)

Expand Down

0 comments on commit 978c109

Please sign in to comment.