make TestRPC tests reliably wait for HTTP server to start (#505)

* make TestRPC tests reliably wait for HTTP server to start

* adjust the wait period to be limited by 3 seconds
This commit is contained in:
Dmitry Verkhoturov
2019-12-29 16:23:47 -06:00
committed by Umputun
parent 828aeda9b1
commit 36b4f6774c
@@ -401,7 +401,13 @@ func prepTestStore(t *testing.T) (s *RPC, port int, teardown func()) {
log.Printf("%v", s.Run(port))
}()
time.Sleep(time.Millisecond * 50) // wait for server to start
// wait for up to 3 seconds for server to start before returning it
for i := 0; i < 300; i++ {
time.Sleep(time.Millisecond * 10)
if _, err := http.Get(fmt.Sprintf("http://localhost:%d", port)); err == nil {
break
}
}
return s, port, func() {
require.NoError(t, s.Shutdown())