Pārlūkot izejas kodu

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 <dug@us.ibm.com>
Doug Davis 10 gadi atpakaļ
vecāks
revīzija
72b75cd4e7
1 mainītis faili ar 45 papildinājumiem un 5 dzēšanām
  1. 45 5
      integration-cli/docker_cli_exec_test.go

+ 45 - 5
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 != "<no value>" {
+			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 == "<no value>" {
-		c.Fatalf("ExecIDs should not be empty, got: %s", out)
+	if out != "[]" && out != "<no value>" {
+		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)
 	}
 }