From 555ce0cb54943dab39f16582fc1923467e42af14 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Fri, 12 Sep 2014 11:42:12 +0400 Subject: [PATCH 1/3] Use defined variable Signed-off-by: Alexandr Morozov --- daemon/container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/container.go b/daemon/container.go index 343a5e8f1c..d33721af16 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -750,7 +750,7 @@ func (container *Container) GetSize() (int64, int64) { } defer container.Unmount() - if differ, ok := container.daemon.driver.(graphdriver.Differ); ok { + if differ, ok := driver.(graphdriver.Differ); ok { sizeRw, err = differ.DiffSize(container.ID) if err != nil { log.Errorf("Warning: driver %s couldn't return diff size of container %s: %s", driver, container.ID, err) From 82bdd88e9c9db40ee8072f7c4c2832dfb3f73823 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Fri, 12 Sep 2014 11:44:25 +0400 Subject: [PATCH 2/3] Use unlocked version of changes for GetImage Fixes #7999 Signed-off-by: Alexandr Morozov --- daemon/container.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index d33721af16..e45ec68d52 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -686,10 +686,14 @@ func (container *Container) Mount() error { return container.daemon.Mount(container) } +func (container *Container) changes() ([]archive.Change, error) { + return container.daemon.Changes(container) +} + func (container *Container) Changes() ([]archive.Change, error) { container.Lock() defer container.Unlock() - return container.daemon.Changes(container) + return container.changes() } func (container *Container) GetImage() (*image.Image, error) { @@ -759,7 +763,7 @@ func (container *Container) GetSize() (int64, int64) { sizeRw = -1 } } else { - changes, _ := container.Changes() + changes, _ := container.changes() if changes != nil { sizeRw = archive.ChangesSize(container.basefs, changes) } else { From 41cbce8c005c201169e13902d62112ced9902928 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Fri, 12 Sep 2014 11:45:50 +0400 Subject: [PATCH 3/3] Test for docker ps -s Signed-off-by: Alexandr Morozov --- integration-cli/docker_cli_ps_test.go | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 4ff3012194..631a27ce9e 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -4,6 +4,7 @@ import ( "os/exec" "strings" "testing" + "time" ) func TestListContainers(t *testing.T) { @@ -199,3 +200,39 @@ func assertContainerList(out string, expected []string) bool { return true } + +func TestListContainersSize(t *testing.T) { + name := "test_size" + runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") + out, _, err := runCommandWithOutput(runCmd) + errorOut(err, t, out) + id, err := getIDByName(name) + if err != nil { + t.Fatal(err) + } + + runCmd = exec.Command(dockerBinary, "ps", "-s", "-n=1") + wait := make(chan struct{}) + go func() { + out, _, err = runCommandWithOutput(runCmd) + close(wait) + }() + select { + case <-wait: + case <-time.After(3 * time.Second): + t.Fatalf("Calling \"docker ps -s\" timed out!") + } + errorOut(err, t, out) + lines := strings.Split(strings.Trim(out, "\n "), "\n") + sizeIndex := strings.Index(lines[0], "SIZE") + idIndex := strings.Index(lines[0], "CONTAINER ID") + foundID := lines[1][idIndex : idIndex+12] + if foundID != id[:12] { + t.Fatalf("Expected id %s, got %s", id[:12], foundID) + } + expectedSize := "2 B" + foundSize := lines[1][sizeIndex:] + if foundSize != expectedSize { + t.Fatalf("Expected size %q, got %q", expectedSize, foundSize) + } +}