blob: 4f70efc310d017956edabfc28c2204bdf1b5d5c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package loggers
import (
"testing"
"time"
)
// Regression: during an interactive prompt, dlog.Common.Pause() unblocks when some
// goroutine hits stdout.log(); that goroutine must not hold the stdout mutex while
// waiting on resume, or dlog.Client.Info from the prompt callback deadlocks forever.
func TestStdoutSecondLogDuringPauseWaitDoesNotDeadlock(t *testing.T) {
s := newStdout()
go s.Pause()
time.Sleep(50 * time.Millisecond)
go func() {
s.Log(time.Now(), "first log consumes pause and waits on resume")
}()
time.Sleep(50 * time.Millisecond)
secondDone := make(chan struct{})
go func() {
s.Log(time.Now(), "second log must acquire mutex while first waits for Resume")
close(secondDone)
}()
select {
case <-secondDone:
case <-time.After(2 * time.Second):
t.Fatal("deadlock: second Log blocked on mutex while first waits for Resume")
}
s.Resume()
time.Sleep(50 * time.Millisecond)
}
|