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
This commit is contained in:
Dave Cheney 2012-12-13 16:26:20 +11:00
parent 641d152935
commit ae12e96350

View file

@ -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)
}