Bladeren bron

Merge pull request #19979 from mavenugo/gccgoci

Use waitRun in TestDockerNetworkHostModeUngracefulDaemonRestart
Tibor Vass 9 jaren geleden
bovenliggende
commit
f0a58947ab
2 gewijzigde bestanden met toevoegingen van 15 en 5 verwijderingen
  1. 4 4
      integration-cli/docker_cli_network_unix_test.go
  2. 11 1
      integration-cli/docker_utils.go

+ 4 - 4
integration-cli/docker_cli_network_unix_test.go

@@ -1017,14 +1017,14 @@ func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c
 	if err := s.d.cmd.Process.Kill(); err != nil {
 	if err := s.d.cmd.Process.Kill(); err != nil {
 		c.Fatal(err)
 		c.Fatal(err)
 	}
 	}
-	s.d.Restart()
+	if err := s.d.Restart(); err != nil {
+		c.Fatal(err)
+	}
 
 
 	// make sure all the containers are up and running
 	// make sure all the containers are up and running
 	for i := 0; i < 10; i++ {
 	for i := 0; i < 10; i++ {
-		cName := fmt.Sprintf("hostc-%d", i)
-		runningOut, err := s.d.Cmd("inspect", "--format='{{.State.Running}}'", cName)
+		err := s.d.waitRun(fmt.Sprintf("hostc-%d", i))
 		c.Assert(err, checker.IsNil)
 		c.Assert(err, checker.IsNil)
-		c.Assert(strings.TrimSpace(runningOut), checker.Equals, "true")
 	}
 	}
 }
 }
 
 

+ 11 - 1
integration-cli/docker_utils.go

@@ -458,6 +458,11 @@ func (d *Daemon) sock() string {
 	return fmt.Sprintf("unix://%s/docker.sock", d.folder)
 	return fmt.Sprintf("unix://%s/docker.sock", d.folder)
 }
 }
 
 
+func (d *Daemon) waitRun(contID string) error {
+	args := []string{"--host", d.sock()}
+	return waitInspectWithArgs(contID, "{{.State.Running}}", "true", 10*time.Second, args...)
+}
+
 // Cmd will execute a docker CLI command against this Daemon.
 // Cmd will execute a docker CLI command against this Daemon.
 // Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version
 // Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version
 func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
 func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
@@ -1685,10 +1690,15 @@ func waitExited(contID string, duration time.Duration) error {
 // in the inspect output. It will wait until the specified timeout (in seconds)
 // in the inspect output. It will wait until the specified timeout (in seconds)
 // is reached.
 // is reached.
 func waitInspect(name, expr, expected string, timeout time.Duration) error {
 func waitInspect(name, expr, expected string, timeout time.Duration) error {
+	return waitInspectWithArgs(name, expr, expected, timeout)
+}
+
+func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg ...string) error {
 	after := time.After(timeout)
 	after := time.After(timeout)
 
 
+	args := append(arg, "inspect", "-f", expr, name)
 	for {
 	for {
-		cmd := exec.Command(dockerBinary, "inspect", "-f", expr, name)
+		cmd := exec.Command(dockerBinary, args...)
 		out, _, err := runCommandWithOutput(cmd)
 		out, _, err := runCommandWithOutput(cmd)
 		if err != nil {
 		if err != nil {
 			if !strings.Contains(out, "No such") {
 			if !strings.Contains(out, "No such") {