Fix race in test registry setup
Wait for the local registry-v2 test instance to become available to avoid random tests failures. Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
parent
bb4d24de06
commit
de8ea06d7d
2 changed files with 26 additions and 0 deletions
|
@ -870,5 +870,18 @@ func setupRegistry(t *testing.T) func() {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Wait for registry to be ready to serve requests.
|
||||
for i := 0; i != 5; i++ {
|
||||
if err = reg.Ping(); err == nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("Timeout waiting for test registry to become available")
|
||||
}
|
||||
|
||||
return func() { reg.Close() }
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -52,6 +53,18 @@ http:
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (t *testRegistryV2) Ping() error {
|
||||
// We always ping through HTTP for our test registry.
|
||||
resp, err := http.Get(fmt.Sprintf("http://%s/v2/", privateRegistryURL))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("registry ping replied with an unexpected status code %s", resp.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *testRegistryV2) Close() {
|
||||
r.cmd.Process.Kill()
|
||||
os.RemoveAll(r.dir)
|
||||
|
|
Loading…
Reference in a new issue