Browse code

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 authored on 2015/07/10 12:57:03
Showing 1 changed files
... ...
@@ -5,6 +5,7 @@ package main
5 5
 import (
6 6
 	"bufio"
7 7
 	"fmt"
8
+	"net/http"
8 9
 	"os"
9 10
 	"os/exec"
10 11
 	"path/filepath"
... ...
@@ -427,19 +428,58 @@ func (s *DockerSuite) TestInspectExecID(c *check.C) {
427 427
 		c.Fatalf("ExecIDs should be empty, got: %s", out)
428 428
 	}
429 429
 
430
-	exitCode, err = runCommand(exec.Command(dockerBinary, "exec", "-d", id, "top"))
431
-	if exitCode != 0 || err != nil {
432
-		c.Fatalf("failed to exec in container: %s, %v", out, err)
430
+	// Start an exec, have it block waiting for input so we can do some checking
431
+	cmd := exec.Command(dockerBinary, "exec", "-i", id, "sh", "-c", "read a")
432
+	execStdin, _ := cmd.StdinPipe()
433
+
434
+	if err = cmd.Start(); err != nil {
435
+		c.Fatalf("failed to start the exec cmd: %q", err)
436
+	}
437
+
438
+	// Since its still running we should see the exec as part of the container
439
+	out, err = inspectField(id, "ExecIDs")
440
+	if err != nil {
441
+		c.Fatalf("failed to inspect container: %s, %v", out, err)
442
+	}
443
+
444
+	// Give the exec 10 chances/seconds to start then give up and stop the test
445
+	tries := 10
446
+	for i := 0; i < tries; i++ {
447
+		out = strings.TrimSuffix(out, "\n")
448
+		if out != "[]" && out != "<no value>" {
449
+			break
450
+		}
451
+		if i == tries {
452
+			c.Fatalf("ExecIDs should not be empty, got: %s", out)
453
+		}
454
+		time.Sleep(1 * time.Second)
455
+	}
456
+
457
+	// Save execID for later
458
+	execID, err := inspectFilter(id, "index .ExecIDs 0")
459
+	if err != nil {
460
+		c.Fatalf("failed to get the exec id")
433 461
 	}
434 462
 
463
+	// End the exec by closing its stdin, and wait for it to end
464
+	execStdin.Close()
465
+	cmd.Wait()
466
+
467
+	// All execs for the container should be gone now
435 468
 	out, err = inspectField(id, "ExecIDs")
436 469
 	if err != nil {
437 470
 		c.Fatalf("failed to inspect container: %s, %v", out, err)
438 471
 	}
439 472
 
440 473
 	out = strings.TrimSuffix(out, "\n")
441
-	if out == "[]" || out == "<no value>" {
442
-		c.Fatalf("ExecIDs should not be empty, got: %s", out)
474
+	if out != "[]" && out != "<no value>" {
475
+		c.Fatalf("ExecIDs should be empty, got: %s", out)
476
+	}
477
+
478
+	// But we should still be able to query the execID
479
+	sc, body, err := sockRequest("GET", "/exec/"+execID+"/json", nil)
480
+	if sc != http.StatusOK {
481
+		c.Fatalf("received status != 200 OK: %s\n%s", sc, body)
443 482
 	}
444 483
 }
445 484