+// Wait (up to 1 second) for keepproxy to listen on a port. This
+// avoids a race condition where we hit a "connection refused" error
+// because we start testing the proxy too soon.
+func waitForListener() {
+ const (ms = 5)
+ for i := 0; listener == nil && i < 1000; i += ms {
+ time.Sleep(ms * time.Millisecond)
+ }
+ if listener == nil {
+ log.Fatalf("Timed out waiting for listener to start")
+ }
+}
+
+func closeListener() {
+ if listener != nil {
+ listener.Close()
+ }
+}
+