mirror of https://github.com/docker/docs.git
				
				
				
			Merge pull request #15412 from vdemeester/dont-sleep-too-much
time.Sleep in integration tests — comment and waitRun/waitInspect
This commit is contained in:
		
						commit
						5929502b4e
					
				|  | @ -767,9 +767,7 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) { | ||||||
| func (s *DockerSuite) TestContainerApiTop(c *check.C) { | func (s *DockerSuite) TestContainerApiTop(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top") | ||||||
| 	id := strings.TrimSpace(string(out)) | 	id := strings.TrimSpace(string(out)) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	type topResp struct { | 	type topResp struct { | ||||||
| 		Titles    []string | 		Titles    []string | ||||||
|  |  | ||||||
|  | @ -14,9 +14,7 @@ import ( | ||||||
| func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) { | func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done") | 	out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done") | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	type logOut struct { | 	type logOut struct { | ||||||
| 		out string | 		out string | ||||||
|  |  | ||||||
|  | @ -17,8 +17,7 @@ func (s *DockerSuite) TestCliStatsNoStreamGetCpu(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done") | ||||||
| 
 | 
 | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	err := waitRun(id) | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 	c.Assert(err, check.IsNil) |  | ||||||
| 
 | 
 | ||||||
| 	resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "") | 	resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "") | ||||||
| 	c.Assert(err, check.IsNil) | 	c.Assert(err, check.IsNil) | ||||||
|  | @ -79,8 +78,7 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) { | ||||||
| 	// Run container for 30 secs
 | 	// Run container for 30 secs
 | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	err := waitRun(id) | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 	c.Assert(err, check.IsNil) |  | ||||||
| 
 | 
 | ||||||
| 	// Retrieve the container address
 | 	// Retrieve the container address
 | ||||||
| 	contIP := findContainerIP(c, id) | 	contIP := findContainerIP(c, id) | ||||||
|  |  | ||||||
|  | @ -90,9 +90,7 @@ func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") | 	out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") | ||||||
| 
 | 
 | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		cmd := exec.Command(dockerBinary, "kill", id) | 		cmd := exec.Command(dockerBinary, "kill", id) | ||||||
|  |  | ||||||
|  | @ -19,9 +19,7 @@ func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-dti", "busybox", "sleep", "2") | 	out, _ := dockerCmd(c, "run", "-dti", "busybox", "sleep", "2") | ||||||
| 
 | 
 | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	errChan := make(chan error) | 	errChan := make(chan error) | ||||||
| 	go func() { | 	go func() { | ||||||
|  | @ -73,10 +71,8 @@ func (s *DockerSuite) TestAttachAfterDetach(c *check.C) { | ||||||
| 		close(errChan) | 		close(errChan) | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
| 	time.Sleep(500 * time.Millisecond) | 	c.Assert(waitRun(name), check.IsNil) | ||||||
| 	if err := waitRun(name); err != nil { | 
 | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 	cpty.Write([]byte{16}) | 	cpty.Write([]byte{16}) | ||||||
| 	time.Sleep(100 * time.Millisecond) | 	time.Sleep(100 * time.Millisecond) | ||||||
| 	cpty.Write([]byte{17}) | 	cpty.Write([]byte{17}) | ||||||
|  | @ -137,9 +133,7 @@ func (s *DockerSuite) TestAttachAfterDetach(c *check.C) { | ||||||
| func (s *DockerSuite) TestAttachDetach(c *check.C) { | func (s *DockerSuite) TestAttachDetach(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") | 	out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	cpty, tty, err := pty.Open() | 	cpty, tty, err := pty.Open() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | @ -157,9 +151,7 @@ func (s *DockerSuite) TestAttachDetach(c *check.C) { | ||||||
| 	if err := cmd.Start(); err != nil { | 	if err := cmd.Start(); err != nil { | ||||||
| 		c.Fatal(err) | 		c.Fatal(err) | ||||||
| 	} | 	} | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatalf("error waiting for container to start: %v", err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if _, err := cpty.Write([]byte("hello\n")); err != nil { | 	if _, err := cpty.Write([]byte("hello\n")); err != nil { | ||||||
| 		c.Fatal(err) | 		c.Fatal(err) | ||||||
|  | @ -211,9 +203,7 @@ func (s *DockerSuite) TestAttachDetach(c *check.C) { | ||||||
| func (s *DockerSuite) TestAttachDetachTruncatedID(c *check.C) { | func (s *DockerSuite) TestAttachDetachTruncatedID(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") | 	out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") | ||||||
| 	id := stringid.TruncateID(strings.TrimSpace(out)) | 	id := stringid.TruncateID(strings.TrimSpace(out)) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	cpty, tty, err := pty.Open() | 	cpty, tty, err := pty.Open() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  |  | ||||||
|  | @ -20,12 +20,11 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) { | ||||||
| 	image := "busybox" | 	image := "busybox" | ||||||
| 
 | 
 | ||||||
| 	// Start stopwatch, generate an event
 | 	// Start stopwatch, generate an event
 | ||||||
| 	time.Sleep(time.Second) // so that we don't grab events from previous test occurred in the same second
 | 	time.Sleep(1 * time.Second) // so that we don't grab events from previous test occured in the same second
 | ||||||
| 	start := daemonTime(c) | 	start := daemonTime(c) | ||||||
| 	time.Sleep(time.Second) // remote API precision is only a second, wait a while before creating an event
 |  | ||||||
| 	dockerCmd(c, "tag", image, "timestamptest:1") | 	dockerCmd(c, "tag", image, "timestamptest:1") | ||||||
| 	dockerCmd(c, "rmi", "timestamptest:1") | 	dockerCmd(c, "rmi", "timestamptest:1") | ||||||
| 	time.Sleep(time.Second) // so that until > since
 | 	time.Sleep(1 * time.Second) // so that until > since
 | ||||||
| 	end := daemonTime(c) | 	end := daemonTime(c) | ||||||
| 
 | 
 | ||||||
| 	// List of available time formats to --since
 | 	// List of available time formats to --since
 | ||||||
|  | @ -223,7 +222,7 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *DockerSuite) TestEventsImageTag(c *check.C) { | func (s *DockerSuite) TestEventsImageTag(c *check.C) { | ||||||
| 	time.Sleep(time.Second * 2) // because API has seconds granularity
 | 	time.Sleep(1 * time.Second) // because API has seconds granularity
 | ||||||
| 	since := daemonTime(c).Unix() | 	since := daemonTime(c).Unix() | ||||||
| 	image := "testimageevents:tag" | 	image := "testimageevents:tag" | ||||||
| 	dockerCmd(c, "tag", "busybox", image) | 	dockerCmd(c, "tag", "busybox", image) | ||||||
|  |  | ||||||
|  | @ -186,9 +186,7 @@ func (s *DockerSuite) TestExecTtyCloseStdin(c *check.C) { | ||||||
| func (s *DockerSuite) TestExecTtyWithoutStdin(c *check.C) { | func (s *DockerSuite) TestExecTtyWithoutStdin(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") | 	out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	errChan := make(chan error) | 	errChan := make(chan error) | ||||||
| 	go func() { | 	go func() { | ||||||
|  |  | ||||||
|  | @ -58,14 +58,14 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		c.Fatal(err) | 		c.Fatal(err) | ||||||
| 	} | 	} | ||||||
| 	time.Sleep(time.Second) | 	time.Sleep(1 * time.Second) | ||||||
| 	id2, err := buildImage("order:test_c", | 	id2, err := buildImage("order:test_c", | ||||||
| 		`FROM scratch | 		`FROM scratch | ||||||
| 		MAINTAINER dockerio2`, true) | 		MAINTAINER dockerio2`, true) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		c.Fatal(err) | 		c.Fatal(err) | ||||||
| 	} | 	} | ||||||
| 	time.Sleep(time.Second) | 	time.Sleep(1 * time.Second) | ||||||
| 	id3, err := buildImage("order:test_b", | 	id3, err := buildImage("order:test_b", | ||||||
| 		`FROM scratch | 		`FROM scratch | ||||||
| 		MAINTAINER dockerio3`, true) | 		MAINTAINER dockerio3`, true) | ||||||
|  |  | ||||||
|  | @ -6,7 +6,6 @@ import ( | ||||||
| 	"reflect" | 	"reflect" | ||||||
| 	"regexp" | 	"regexp" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) { | func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) { | ||||||
|  | @ -138,7 +137,7 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) { | ||||||
| 	out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top") | 	out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top") | ||||||
| 	idTwo := strings.TrimSpace(out) | 	idTwo := strings.TrimSpace(out) | ||||||
| 
 | 
 | ||||||
| 	time.Sleep(1 * time.Second) | 	c.Assert(waitRun(idTwo), check.IsNil) | ||||||
| 
 | 
 | ||||||
| 	contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts") | 	contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  |  | ||||||
|  | @ -30,17 +30,13 @@ func (s *DockerSuite) TestPsListContainers(c *check.C) { | ||||||
| 	fourthID := strings.TrimSpace(out) | 	fourthID := strings.TrimSpace(out) | ||||||
| 
 | 
 | ||||||
| 	// make sure the second is running
 | 	// make sure the second is running
 | ||||||
| 	if err := waitRun(secondID); err != nil { | 	c.Assert(waitRun(secondID), check.IsNil) | ||||||
| 		c.Fatalf("waiting for container failed: %v", err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	// make sure third one is not running
 | 	// make sure third one is not running
 | ||||||
| 	dockerCmd(c, "wait", thirdID) | 	dockerCmd(c, "wait", thirdID) | ||||||
| 
 | 
 | ||||||
| 	// make sure the forth is running
 | 	// make sure the forth is running
 | ||||||
| 	if err := waitRun(fourthID); err != nil { | 	c.Assert(waitRun(fourthID), check.IsNil) | ||||||
| 		c.Fatalf("waiting for container failed: %v", err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	// all
 | 	// all
 | ||||||
| 	out, _ = dockerCmd(c, "ps", "-a") | 	out, _ = dockerCmd(c, "ps", "-a") | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/go-check/check" | 	"github.com/go-check/check" | ||||||
| ) | ) | ||||||
|  | @ -31,7 +30,7 @@ func (s *DockerSuite) TestRestartRunningContainer(c *check.C) { | ||||||
| 
 | 
 | ||||||
| 	cleanedContainerID := strings.TrimSpace(out) | 	cleanedContainerID := strings.TrimSpace(out) | ||||||
| 
 | 
 | ||||||
| 	time.Sleep(1 * time.Second) | 	c.Assert(waitRun(cleanedContainerID), check.IsNil) | ||||||
| 
 | 
 | ||||||
| 	out, _ = dockerCmd(c, "logs", cleanedContainerID) | 	out, _ = dockerCmd(c, "logs", cleanedContainerID) | ||||||
| 	if out != "foobar\n" { | 	if out != "foobar\n" { | ||||||
|  | @ -42,7 +41,7 @@ func (s *DockerSuite) TestRestartRunningContainer(c *check.C) { | ||||||
| 
 | 
 | ||||||
| 	out, _ = dockerCmd(c, "logs", cleanedContainerID) | 	out, _ = dockerCmd(c, "logs", cleanedContainerID) | ||||||
| 
 | 
 | ||||||
| 	time.Sleep(1 * time.Second) | 	c.Assert(waitRun(cleanedContainerID), check.IsNil) | ||||||
| 
 | 
 | ||||||
| 	if out != "foobar\nfoobar\n" { | 	if out != "foobar\nfoobar\n" { | ||||||
| 		c.Errorf("container should've printed 'foobar' twice") | 		c.Errorf("container should've printed 'foobar' twice") | ||||||
|  |  | ||||||
|  | @ -1995,9 +1995,7 @@ func (s *DockerSuite) TestContainerNetworkMode(c *check.C) { | ||||||
| 
 | 
 | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 	pid1, err := inspectField(id, "State.Pid") | 	pid1, err := inspectField(id, "State.Pid") | ||||||
| 	c.Assert(err, check.IsNil) | 	c.Assert(err, check.IsNil) | ||||||
| 
 | 
 | ||||||
|  | @ -2362,7 +2360,8 @@ func (s *DockerSuite) TestRunPidHostWithChildIsKillable(c *check.C) { | ||||||
| 	name := "ibuildthecloud" | 	name := "ibuildthecloud" | ||||||
| 	dockerCmd(c, "run", "-d", "--pid=host", "--name", name, "busybox", "sh", "-c", "sleep 30; echo hi") | 	dockerCmd(c, "run", "-d", "--pid=host", "--name", name, "busybox", "sh", "-c", "sleep 30; echo hi") | ||||||
| 
 | 
 | ||||||
| 	time.Sleep(1 * time.Second) | 	c.Assert(waitRun(name), check.IsNil) | ||||||
|  | 
 | ||||||
| 	errchan := make(chan error) | 	errchan := make(chan error) | ||||||
| 	go func() { | 	go func() { | ||||||
| 		if out, _, err := dockerCmdWithError("kill", name); err != nil { | 		if out, _, err := dockerCmdWithError("kill", name); err != nil { | ||||||
|  | @ -2778,9 +2777,7 @@ func (s *DockerSuite) TestPtraceContainerProcsFromHost(c *check.C) { | ||||||
| 
 | 
 | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 	pid1, err := inspectField(id, "State.Pid") | 	pid1, err := inspectField(id, "State.Pid") | ||||||
| 	c.Assert(err, check.IsNil) | 	c.Assert(err, check.IsNil) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -198,9 +198,7 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) { | ||||||
| 	if err := cmd.Start(); err != nil { | 	if err := cmd.Start(); err != nil { | ||||||
| 		c.Fatal(err) | 		c.Fatal(err) | ||||||
| 	} | 	} | ||||||
| 	if err := waitRun(name); err != nil { | 	c.Assert(waitRun(name), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if _, err := cpty.Write([]byte("hello\n")); err != nil { | 	if _, err := cpty.Write([]byte("hello\n")); err != nil { | ||||||
| 		c.Fatal(err) | 		c.Fatal(err) | ||||||
|  |  | ||||||
|  | @ -11,9 +11,7 @@ import ( | ||||||
| func (s *DockerSuite) TestCliStatsNoStream(c *check.C) { | func (s *DockerSuite) TestCliStatsNoStream(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top") | ||||||
| 	id := strings.TrimSpace(out) | 	id := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(id); err != nil { | 	c.Assert(waitRun(id), check.IsNil) | ||||||
| 		c.Fatalf("error waiting for container to start: %v", err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id) | 	statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id) | ||||||
| 	chErr := make(chan error) | 	chErr := make(chan error) | ||||||
|  |  | ||||||
|  | @ -14,16 +14,8 @@ func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "true") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "true") | ||||||
| 	containerID := strings.TrimSpace(out) | 	containerID := strings.TrimSpace(out) | ||||||
| 
 | 
 | ||||||
| 	status := "true" | 	if err := waitInspect(containerID, "{{.State.Running}}", "false", 1); err != nil { | ||||||
| 	var err error | 		c.Fatal("Container should have stopped by now") | ||||||
| 	for i := 0; status != "false"; i++ { |  | ||||||
| 		status, err = inspectField(containerID, "State.Running") |  | ||||||
| 		c.Assert(err, check.IsNil) |  | ||||||
| 
 |  | ||||||
| 		time.Sleep(time.Second) |  | ||||||
| 		if i >= 60 { |  | ||||||
| 			c.Fatal("Container should have stopped by now") |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	out, _ = dockerCmd(c, "wait", containerID) | 	out, _ = dockerCmd(c, "wait", containerID) | ||||||
|  | @ -38,9 +30,7 @@ func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' TERM; while true; do sleep 0.01; done") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' TERM; while true; do sleep 0.01; done") | ||||||
| 	containerID := strings.TrimSpace(out) | 	containerID := strings.TrimSpace(out) | ||||||
| 
 | 
 | ||||||
| 	if err := waitRun(containerID); err != nil { | 	c.Assert(waitRun(containerID), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	chWait := make(chan string) | 	chWait := make(chan string) | ||||||
| 	go func() { | 	go func() { | ||||||
|  | @ -67,16 +57,8 @@ func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "exit 99") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "exit 99") | ||||||
| 	containerID := strings.TrimSpace(out) | 	containerID := strings.TrimSpace(out) | ||||||
| 
 | 
 | ||||||
| 	status := "true" | 	if err := waitInspect(containerID, "{{.State.Running}}", "false", 1); err != nil { | ||||||
| 	var err error | 		c.Fatal("Container should have stopped by now") | ||||||
| 	for i := 0; status != "false"; i++ { |  | ||||||
| 		status, err = inspectField(containerID, "State.Running") |  | ||||||
| 		c.Assert(err, check.IsNil) |  | ||||||
| 
 |  | ||||||
| 		time.Sleep(time.Second) |  | ||||||
| 		if i >= 60 { |  | ||||||
| 			c.Fatal("Container should have stopped by now") |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	out, _ = dockerCmd(c, "wait", containerID) | 	out, _ = dockerCmd(c, "wait", containerID) | ||||||
|  | @ -90,12 +72,7 @@ func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) { | ||||||
| func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) { | func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) { | ||||||
| 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 99' TERM; while true; do sleep 0.01; done") | 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 99' TERM; while true; do sleep 0.01; done") | ||||||
| 	containerID := strings.TrimSpace(out) | 	containerID := strings.TrimSpace(out) | ||||||
| 	if err := waitRun(containerID); err != nil { | 	c.Assert(waitRun(containerID), check.IsNil) | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 	if err := waitRun(containerID); err != nil { |  | ||||||
| 		c.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	chWait := make(chan error) | 	chWait := make(chan error) | ||||||
| 	waitCmd := exec.Command(dockerBinary, "wait", containerID) | 	waitCmd := exec.Command(dockerBinary, "wait", containerID) | ||||||
|  |  | ||||||
|  | @ -1240,10 +1240,12 @@ func runCommandAndReadContainerFile(filename string, cmd *exec.Cmd) ([]byte, err | ||||||
| 		return nil, fmt.Errorf("%v: %q", err, out) | 		return nil, fmt.Errorf("%v: %q", err, out) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	time.Sleep(1 * time.Second) |  | ||||||
| 
 |  | ||||||
| 	contID := strings.TrimSpace(out) | 	contID := strings.TrimSpace(out) | ||||||
| 
 | 
 | ||||||
|  | 	if err := waitRun(contID); err != nil { | ||||||
|  | 		return nil, fmt.Errorf("%v: %q", contID, err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return readContainerFile(contID, filename) | 	return readContainerFile(contID, filename) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -196,10 +196,14 @@ func waitForContainer(contID string, args ...string) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // waitRun will wait for the specified container to be running, maximum 5 seconds.
 | ||||||
| func waitRun(contID string) error { | func waitRun(contID string) error { | ||||||
| 	return waitInspect(contID, "{{.State.Running}}", "true", 5) | 	return waitInspect(contID, "{{.State.Running}}", "true", 5) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // waitInspect will wait for the specified container to have the specified string
 | ||||||
|  | // in the inspect output. It will wait until the specified timeout (in seconds)
 | ||||||
|  | // is reached.
 | ||||||
| func waitInspect(name, expr, expected string, timeout int) error { | func waitInspect(name, expr, expected string, timeout int) error { | ||||||
| 	after := time.After(time.Duration(timeout) * time.Second) | 	after := time.After(time.Duration(timeout) * time.Second) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue