1
0
mirror of https://github.com/golang/go synced 2024-11-26 04:17:59 -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:
Dmitriy Vyukov 2013-05-24 18:35:48 +04:00
parent 2ca589d494
commit 0806c97209

View File

@ -281,12 +281,12 @@ func TestConcurrentWrite(t *testing.T) {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done()
err := w.Info("test") err := w.Info("test")
if err != nil { if err != nil {
t.Errorf("Info() failed: %v", err) t.Errorf("Info() failed: %v", err)
return return
} }
wg.Done()
}() }()
} }
wg.Wait() wg.Wait()
@ -296,8 +296,10 @@ func TestConcurrentReconnect(t *testing.T) {
crashy = true crashy = true
defer func() { crashy = false }() defer func() { crashy = false }()
const N = 10
const M = 100
net := "unix" net := "unix"
done := make(chan string) done := make(chan string, N*M)
addr, sock, srvWG := startServer(net, "", done) addr, sock, srvWG := startServer(net, "", done)
defer os.Remove(addr) defer os.Remove(addr)
@ -310,7 +312,7 @@ func TestConcurrentReconnect(t *testing.T) {
// we are looking for 500 out of 1000 events // we are looking for 500 out of 1000 events
// here because lots of log messages are lost // here because lots of log messages are lost
// in buffers (kernel and/or bufio) // in buffers (kernel and/or bufio)
if ct > 500 { if ct > N*M/2 {
break break
} }
} }
@ -318,21 +320,21 @@ func TestConcurrentReconnect(t *testing.T) {
}() }()
var wg sync.WaitGroup var wg sync.WaitGroup
for i := 0; i < 10; i++ { wg.Add(N)
wg.Add(1) for i := 0; i < N; i++ {
go func() { go func() {
defer wg.Done()
w, err := Dial(net, addr, LOG_USER|LOG_ERR, "tag") w, err := Dial(net, addr, LOG_USER|LOG_ERR, "tag")
if err != nil { if err != nil {
t.Fatalf("syslog.Dial() failed: %v", err) t.Fatalf("syslog.Dial() failed: %v", err)
} }
for i := 0; i < 100; i++ { for i := 0; i < M; i++ {
err := w.Info("test") err := w.Info("test")
if err != nil { if err != nil {
t.Errorf("Info() failed: %v", err) t.Errorf("Info() failed: %v", err)
return return
} }
} }
wg.Done()
}() }()
} }
wg.Wait() wg.Wait()