git » dnss » commit 9195e1a

testing: Fix how we wait for servers to come up

author Alberto Bertogli
2016-08-20 11:33:28 UTC
committer Alberto Bertogli
2016-08-20 11:50:50 UTC
parent 1dfd282e0192a4627b7fcac12e2abb4103f1ce82

testing: Fix how we wait for servers to come up

The current way we wait for servers to come up will fail if the server returns
an error, which happens if the other side is listening but not ready.

This patch fixes it by retrying on errors too, up until the deadline.

testing/util/util.go +4 -6

diff --git a/testing/util/util.go b/testing/util/util.go
index c59d72b..52a080f 100644
--- a/testing/util/util.go
+++ b/testing/util/util.go
@@ -24,12 +24,10 @@ func WaitForDNSServer(addr string) error {
 	m := &dns.Msg{}
 	m.SetQuestion("unused.", dns.TypeA)
 
-	after := time.After(5 * time.Second)
+	deadline := time.Now().Add(5 * time.Second)
 	tick := time.Tick(100 * time.Millisecond)
-	select {
-	case <-after:
-		return fmt.Errorf("timed out")
-	case <-tick:
+
+	for (<-tick).Before(deadline) {
 		conn.SetDeadline(time.Now().Add(1 * time.Second))
 		conn.WriteMsg(m)
 		_, err := conn.ReadMsg()
@@ -38,7 +36,7 @@ func WaitForDNSServer(addr string) error {
 		}
 	}
 
-	return fmt.Errorf("not reachable")
+	return fmt.Errorf("timed out")
 }
 
 // Get a free (TCP) port. This is hacky and not race-free, but it works well