Browse Source

Merge pull request #10487 from icecrime/racy_test_registry

Fix race in test registry setup
Tibor Vass 10 years ago
parent
commit
fcdfc8ccc8
2 changed files with 26 additions and 0 deletions
  1. 13 0
      integration-cli/docker_utils.go
  2. 13 0
      integration-cli/registry.go

+ 13 - 0
integration-cli/docker_utils.go

@@ -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() }
 }

+ 13 - 0
integration-cli/registry.go

@@ -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)