Skip to content

Commit

Permalink
fix: log test data race (testcontainers#2863)
Browse files Browse the repository at this point in the history
Fix a data race when accessing logger in consumer test.
  • Loading branch information
stevenh authored Oct 30, 2024
1 parent 3f2f0d0 commit a489482
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions logconsumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,24 @@ func Test_StartLogProductionStillStartsWithTooHighTimeout(t *testing.T) {

// bufLogger is a Logging implementation that writes to a bytes.Buffer.
type bufLogger struct {
bytes.Buffer
mtx sync.Mutex
buf bytes.Buffer
}

// Printf implements Logging.
func (l *bufLogger) Printf(format string, v ...any) {
fmt.Fprintf(l, format, v...)
l.mtx.Lock()
defer l.mtx.Unlock()

fmt.Fprintf(&l.buf, format, v...)
}

// String returns the contents of the buffer as a string.
func (l *bufLogger) String() string {
l.mtx.Lock()
defer l.mtx.Unlock()

return l.buf.String()
}

func Test_MultiContainerLogConsumer_CancelledContext(t *testing.T) {
Expand Down

0 comments on commit a489482

Please sign in to comment.