Fix command tests that wait for client to be registered
This commit is contained in:
parent
0f3ec9c759
commit
416ed7692e
|
@ -186,6 +186,11 @@ func NewTestServer(t *testing.T, cb ServerConfigCallback) *TestServer {
|
|||
} else {
|
||||
server.waitForAPI()
|
||||
}
|
||||
|
||||
// Wait for the client to be ready
|
||||
if nomadConfig.DevMode {
|
||||
server.waitForClient()
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
|
@ -249,6 +254,44 @@ func (s *TestServer) waitForLeader() {
|
|||
})
|
||||
}
|
||||
|
||||
// waitForClient waits for the Nomad client to be ready. The function returns
|
||||
// immediately if the server is not in dev mode.
|
||||
func (s *TestServer) waitForClient() {
|
||||
if !s.Config.DevMode {
|
||||
return
|
||||
}
|
||||
|
||||
WaitForResult(func() (bool, error) {
|
||||
resp, err := s.HTTPClient.Get(s.url("/v1/nodes"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if err := s.requireOK(resp); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var decoded []struct {
|
||||
ID string
|
||||
Status string
|
||||
}
|
||||
|
||||
dec := json.NewDecoder(resp.Body)
|
||||
if err := dec.Decode(&decoded); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if len(decoded) != 1 || decoded[0].Status != "ready" {
|
||||
return false, fmt.Errorf("Node not ready: %v", decoded)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
defer s.Stop()
|
||||
s.t.Fatalf("err: %s", err)
|
||||
})
|
||||
}
|
||||
|
||||
// url is a helper function which takes a relative URL and
|
||||
// makes it into a proper URL against the local Nomad server.
|
||||
func (s *TestServer) url(path string) string {
|
||||
|
|
Loading…
Reference in a new issue