Commit ae12e963 authored by Dave Cheney's avatar Dave Cheney

log/syslog: fix flakey test on slow hosts

Fixes #4467.

The syslog tests can fail if the timeout fires before the data arrives at the mock server. Moving the timeout onto the goroutine that is calling ReadFrom() and always processing the data returned before handling the error should improve the reliability of the test.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6920047
parent 641d1529
......@@ -20,13 +20,14 @@ var serverAddr string
func runSyslog(c net.PacketConn, done chan<- string) {
var buf [4096]byte
var rcvd string = ""
var rcvd string
for {
n, _, err := c.ReadFrom(buf[0:])
if err != nil || n == 0 {
c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
n, _, err := c.ReadFrom(buf[:])
rcvd += string(buf[:n])
if err != nil {
break
}
rcvd += string(buf[0:n])
}
done <- rcvd
}
......@@ -37,7 +38,6 @@ func startServer(done chan<- string) {
log.Fatalf("net.ListenPacket failed udp :0 %v", e)
}
serverAddr = c.LocalAddr().String()
c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
go runSyslog(c, done)
}
......
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