mirror of https://github.com/docker/docs.git
Merge pull request #10487 from icecrime/racy_test_registry
Fix race in test registry setup
This commit is contained in:
commit
fcdfc8ccc8
|
@ -870,5 +870,18 @@ func setupRegistry(t *testing.T) func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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() }
|
return func() { reg.Close() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -52,6 +53,18 @@ http:
|
||||||
}, nil
|
}, 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() {
|
func (r *testRegistryV2) Close() {
|
||||||
r.cmd.Process.Kill()
|
r.cmd.Process.Kill()
|
||||||
os.RemoveAll(r.dir)
|
os.RemoveAll(r.dir)
|
||||||
|
|
Loading…
Reference in New Issue