From 0f1eca72654a138a7805e2c21e6a334a3145384b Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 29 Sep 2015 14:50:22 +0200 Subject: [PATCH] Fix TestDockerCmd*Timeout racey tests Signed-off-by: Vincent Demeester --- integration/dockerCmd_utils_test.go | 5 ++--- integration/utils.go | 10 +++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/integration/dockerCmd_utils_test.go b/integration/dockerCmd_utils_test.go index 1b88e6b..b7c9671 100644 --- a/integration/dockerCmd_utils_test.go +++ b/integration/dockerCmd_utils_test.go @@ -160,7 +160,6 @@ func (s *DockerCmdSuite) TestDockerCmdSuccess(c *check.C) { // DockerCmdWithTimeout tests func (s *DockerCmdSuite) TestDockerCmdWithTimeout(c *check.C) { - c.Skip("racey test") cmds := []struct { binary string args []string @@ -269,7 +268,6 @@ func (s *DockerCmdSuite) TestDockerCmdInDir(c *check.C) { // DockerCmdInDirWithTimeout tests func (s *DockerCmdSuite) TestDockerCmdInDirWithTimeout(c *check.C) { - c.Skip("racey test") tempFolder, err := ioutil.TempDir("", "test-docker-cmd-in-dir") c.Assert(err, check.IsNil) @@ -391,7 +389,8 @@ func TestHelperProcess(t *testing.T) { case "a command that times out": time.Sleep(10 * time.Millisecond) fmt.Fprintf(os.Stdout, "too long, should be killed") - os.Exit(0) + // A random exit code (that should never happened in tests) + os.Exit(7) case "run -ti ubuntu echo hello": fmt.Fprintf(os.Stdout, "hello") default: diff --git a/integration/utils.go b/integration/utils.go index 469f720..6fe1c0a 100644 --- a/integration/utils.go +++ b/integration/utils.go @@ -105,8 +105,16 @@ func RunCommandWithOutputForDuration(cmd *exec.Cmd, duration time.Duration) (out cmd.Stderr = &outputBuffer done := make(chan error) + + // Start the command in the main thread.. + err = cmd.Start() + if err != nil { + err = fmt.Errorf("Fail to start command %v : %v", cmd, err) + } + go func() { - exitErr := cmd.Run() + // And wait for it to exit in the goroutine :) + exitErr := cmd.Wait() exitCode = ProcessExitCode(exitErr) done <- exitErr }()