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>
| ... | ... |
@@ -870,5 +870,18 @@ func setupRegistry(t *testing.T) func() {
|
| 870 | 870 |
if err != nil {
|
| 871 | 871 |
t.Fatal(err) |
| 872 | 872 |
} |
| 873 |
+ |
|
| 874 |
+ // Wait for registry to be ready to serve requests. |
|
| 875 |
+ for i := 0; i != 5; i++ {
|
|
| 876 |
+ if err = reg.Ping(); err == nil {
|
|
| 877 |
+ break |
|
| 878 |
+ } |
|
| 879 |
+ time.Sleep(100 * time.Millisecond) |
|
| 880 |
+ } |
|
| 881 |
+ |
|
| 882 |
+ if err != nil {
|
|
| 883 |
+ t.Fatal("Timeout waiting for test registry to become available")
|
|
| 884 |
+ } |
|
| 885 |
+ |
|
| 873 | 886 |
return func() { reg.Close() }
|
| 874 | 887 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"io/ioutil" |
| 6 |
+ "net/http" |
|
| 6 | 7 |
"os" |
| 7 | 8 |
"os/exec" |
| 8 | 9 |
"path/filepath" |
| ... | ... |
@@ -52,6 +53,18 @@ http: |
| 52 | 52 |
}, nil |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 |
+func (t *testRegistryV2) Ping() error {
|
|
| 56 |
+ // We always ping through HTTP for our test registry. |
|
| 57 |
+ resp, err := http.Get(fmt.Sprintf("http://%s/v2/", privateRegistryURL))
|
|
| 58 |
+ if err != nil {
|
|
| 59 |
+ return err |
|
| 60 |
+ } |
|
| 61 |
+ if resp.StatusCode != 200 {
|
|
| 62 |
+ return fmt.Errorf("registry ping replied with an unexpected status code %s", resp.StatusCode)
|
|
| 63 |
+ } |
|
| 64 |
+ return nil |
|
| 65 |
+} |
|
| 66 |
+ |
|
| 55 | 67 |
func (r *testRegistryV2) Close() {
|
| 56 | 68 |
r.cmd.Process.Kill() |
| 57 | 69 |
os.RemoveAll(r.dir) |