Browse code

Fix TestDockerCmd*Timeout racey tests

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2015/09/29 21:50:22
Showing 2 changed files
... ...
@@ -160,7 +160,6 @@ func (s *DockerCmdSuite) TestDockerCmdSuccess(c *check.C) {
160 160
 // DockerCmdWithTimeout tests
161 161
 
162 162
 func (s *DockerCmdSuite) TestDockerCmdWithTimeout(c *check.C) {
163
-	c.Skip("racey test")
164 163
 	cmds := []struct {
165 164
 		binary           string
166 165
 		args             []string
... ...
@@ -269,7 +268,6 @@ func (s *DockerCmdSuite) TestDockerCmdInDir(c *check.C) {
269 269
 // DockerCmdInDirWithTimeout tests
270 270
 
271 271
 func (s *DockerCmdSuite) TestDockerCmdInDirWithTimeout(c *check.C) {
272
-	c.Skip("racey test")
273 272
 	tempFolder, err := ioutil.TempDir("", "test-docker-cmd-in-dir")
274 273
 	c.Assert(err, check.IsNil)
275 274
 
... ...
@@ -391,7 +389,8 @@ func TestHelperProcess(t *testing.T) {
391 391
 		case "a command that times out":
392 392
 			time.Sleep(10 * time.Millisecond)
393 393
 			fmt.Fprintf(os.Stdout, "too long, should be killed")
394
-			os.Exit(0)
394
+			// A random exit code (that should never happened in tests)
395
+			os.Exit(7)
395 396
 		case "run -ti ubuntu echo hello":
396 397
 			fmt.Fprintf(os.Stdout, "hello")
397 398
 		default:
... ...
@@ -105,8 +105,16 @@ func RunCommandWithOutputForDuration(cmd *exec.Cmd, duration time.Duration) (out
105 105
 	cmd.Stderr = &outputBuffer
106 106
 
107 107
 	done := make(chan error)
108
+
109
+	// Start the command in the main thread..
110
+	err = cmd.Start()
111
+	if err != nil {
112
+		err = fmt.Errorf("Fail to start command %v : %v", cmd, err)
113
+	}
114
+
108 115
 	go func() {
109
-		exitErr := cmd.Run()
116
+		// And wait for it to exit in the goroutine :)
117
+		exitErr := cmd.Wait()
110 118
 		exitCode = ProcessExitCode(exitErr)
111 119
 		done <- exitErr
112 120
 	}()