mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #22969 from AkihiroSuda/fix22963LogRace
Fix a race in daemon/logger.TestCopier
This commit is contained in:
commit
a41e823c1b
1 changed files with 4 additions and 0 deletions
|
@ -4,12 +4,14 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestLoggerJSON struct {
|
type TestLoggerJSON struct {
|
||||||
*json.Encoder
|
*json.Encoder
|
||||||
|
mu sync.Mutex
|
||||||
delay time.Duration
|
delay time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +19,8 @@ func (l *TestLoggerJSON) Log(m *Message) error {
|
||||||
if l.delay > 0 {
|
if l.delay > 0 {
|
||||||
time.Sleep(l.delay)
|
time.Sleep(l.delay)
|
||||||
}
|
}
|
||||||
|
l.mu.Lock()
|
||||||
|
defer l.mu.Unlock()
|
||||||
return l.Encode(m)
|
return l.Encode(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue