Commit 0806c972 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent 2ca589d4
...@@ -281,12 +281,12 @@ func TestConcurrentWrite(t *testing.T) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment