Merge pull request #16582 from vdemeester/16360-dockerCmd-raceytests

Fix TestDockerCmd*Timeout racey tests
This commit is contained in:
Doug Davis 2015-10-02 20:45:41 -04:00
commit fdc3d2821e
2 changed files with 11 additions and 4 deletions

View file

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

View file

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