From e5af4782608b399ed4e753d5b435c2f415bba353 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Thu, 9 Jul 2015 20:57:03 -0700 Subject: [PATCH] More extensive testing of new GC of execs This is a follow-on to PR #14520. PR #14520 is the quick fix to get the testing working again. This PR makes sure that the list of execs associated with a container goes from zero to one (as a new exec is run), then back to zero when the exec is finished. However, we should be able to query the exec while the container is still around, and even though the exec isn't listed in the container's inspect data. Signed-off-by: Doug Davis Upstream-commit: 72b75cd4e764e25cecd3f0c100597b8868c68120 Component: engine --- .../integration-cli/docker_cli_exec_test.go | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/components/engine/integration-cli/docker_cli_exec_test.go b/components/engine/integration-cli/docker_cli_exec_test.go index f41ad85e44..3c59552c7b 100644 --- a/components/engine/integration-cli/docker_cli_exec_test.go +++ b/components/engine/integration-cli/docker_cli_exec_test.go @@ -5,6 +5,7 @@ package main import ( "bufio" "fmt" + "net/http" "os" "os/exec" "path/filepath" @@ -427,19 +428,58 @@ func (s *DockerSuite) TestInspectExecID(c *check.C) { c.Fatalf("ExecIDs should be empty, got: %s", out) } - exitCode, err = runCommand(exec.Command(dockerBinary, "exec", "-d", id, "top")) - if exitCode != 0 || err != nil { - c.Fatalf("failed to exec in container: %s, %v", out, err) + // Start an exec, have it block waiting for input so we can do some checking + cmd := exec.Command(dockerBinary, "exec", "-i", id, "sh", "-c", "read a") + execStdin, _ := cmd.StdinPipe() + + if err = cmd.Start(); err != nil { + c.Fatalf("failed to start the exec cmd: %q", err) } + // Since its still running we should see the exec as part of the container + out, err = inspectField(id, "ExecIDs") + if err != nil { + c.Fatalf("failed to inspect container: %s, %v", out, err) + } + + // Give the exec 10 chances/seconds to start then give up and stop the test + tries := 10 + for i := 0; i < tries; i++ { + out = strings.TrimSuffix(out, "\n") + if out != "[]" && out != "" { + break + } + if i == tries { + c.Fatalf("ExecIDs should not be empty, got: %s", out) + } + time.Sleep(1 * time.Second) + } + + // Save execID for later + execID, err := inspectFilter(id, "index .ExecIDs 0") + if err != nil { + c.Fatalf("failed to get the exec id") + } + + // End the exec by closing its stdin, and wait for it to end + execStdin.Close() + cmd.Wait() + + // All execs for the container should be gone now out, err = inspectField(id, "ExecIDs") if err != nil { c.Fatalf("failed to inspect container: %s, %v", out, err) } out = strings.TrimSuffix(out, "\n") - if out == "[]" || out == "" { - c.Fatalf("ExecIDs should not be empty, got: %s", out) + if out != "[]" && out != "" { + c.Fatalf("ExecIDs should be empty, got: %s", out) + } + + // But we should still be able to query the execID + sc, body, err := sockRequest("GET", "/exec/"+execID+"/json", nil) + if sc != http.StatusOK { + c.Fatalf("received status != 200 OK: %s\n%s", sc, body) } }