]> Cypherpunks repositories - gostls13.git/commitdiff
log/syslog: fix flakey test on slow hosts
authorDave Cheney <dave@cheney.net>
Thu, 13 Dec 2012 05:26:20 +0000 (16:26 +1100)
committerDave Cheney <dave@cheney.net>
Thu, 13 Dec 2012 05:26:20 +0000 (16:26 +1100)
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

src/pkg/log/syslog/syslog_test.go

index 4c0bf1f4e7cd2752c7155d600e92871aaa9f5b7a..67d7103ee44a93896217adebcca33fd26abd11bd 100644 (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)
 }