mirror of
https://github.com/golang/go
synced 2024-11-22 11:04:40 -07:00
log/syslog: fix deadlock in test
The problem was that server handlers block on done<-, the goroutine that reads from done blocks on count<-, and the main goroutine that is supposed to read from count waits for server handlers to exit. Fixes #5547. R=golang-dev, dave, bradfitz CC=golang-dev https://golang.org/cl/9722043
This commit is contained in:
parent
2ca589d494
commit
0806c97209
@ -281,12 +281,12 @@ func TestConcurrentWrite(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err := w.Info("test")
|
||||
if err != nil {
|
||||
t.Errorf("Info() failed: %v", err)
|
||||
return
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
@ -296,8 +296,10 @@ func TestConcurrentReconnect(t *testing.T) {
|
||||
crashy = true
|
||||
defer func() { crashy = false }()
|
||||
|
||||
const N = 10
|
||||
const M = 100
|
||||
net := "unix"
|
||||
done := make(chan string)
|
||||
done := make(chan string, N*M)
|
||||
addr, sock, srvWG := startServer(net, "", done)
|
||||
defer os.Remove(addr)
|
||||
|
||||
@ -310,7 +312,7 @@ func TestConcurrentReconnect(t *testing.T) {
|
||||
// we are looking for 500 out of 1000 events
|
||||
// here because lots of log messages are lost
|
||||
// in buffers (kernel and/or bufio)
|
||||
if ct > 500 {
|
||||
if ct > N*M/2 {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -318,21 +320,21 @@ func TestConcurrentReconnect(t *testing.T) {
|
||||
}()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
w, err := Dial(net, addr, LOG_USER|LOG_ERR, "tag")
|
||||
if err != nil {
|
||||
t.Fatalf("syslog.Dial() failed: %v", err)
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
for i := 0; i < M; i++ {
|
||||
err := w.Info("test")
|
||||
if err != nil {
|
||||
t.Errorf("Info() failed: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
|
Loading…
Reference in New Issue
Block a user