Ver Fonte

Merge pull request #22969 from AkihiroSuda/fix22963LogRace

Fix a race in daemon/logger.TestCopier
Brian Goff há 9 anos atrás
pai
commit
a41e823c1b
1 ficheiros alterados com 4 adições e 0 exclusões
  1. 4 0
      daemon/logger/copier_test.go

+ 4 - 0
daemon/logger/copier_test.go

@@ -4,12 +4,14 @@ import (
 	"bytes"
 	"encoding/json"
 	"io"
+	"sync"
 	"testing"
 	"time"
 )
 
 type TestLoggerJSON struct {
 	*json.Encoder
+	mu    sync.Mutex
 	delay time.Duration
 }
 
@@ -17,6 +19,8 @@ func (l *TestLoggerJSON) Log(m *Message) error {
 	if l.delay > 0 {
 		time.Sleep(l.delay)
 	}
+	l.mu.Lock()
+	defer l.mu.Unlock()
 	return l.Encode(m)
 }