From 5a02c9ba0a8e4dc19001a11d00049ec2c76511f0 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 23 Apr 2013 10:28:40 -0700 Subject: [PATCH 1/4] Make sure the container is well started prior to perform the test --- runtime_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/runtime_test.go b/runtime_test.go index 3964549412..1c2634f1d8 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -273,7 +273,16 @@ func TestAllocatePortLocalhost(t *testing.T) { t.Fatal(err) } defer container.Kill() - time.Sleep(600 * time.Millisecond) // Wait for the container to run + + setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() { + for { + if container.State.Running { + break + } + time.Sleep(10 * time.Millisecond) + } + }) + conn, err := net.Dial("tcp", fmt.Sprintf( "localhost:%s", container.NetworkSettings.PortMapping["5555"], @@ -293,6 +302,7 @@ func TestAllocatePortLocalhost(t *testing.T) { string(output), ) } + container.Wait() } func TestRestore(t *testing.T) { From a22c78523f20c44e90e7a3adbd01a5560ed4f6ae Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 23 Apr 2013 11:09:48 -0700 Subject: [PATCH 2/4] Wait for the container to finish in TestAttachDisconnect before destroying it --- commands_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/commands_test.go b/commands_test.go index a64b4f4dc7..83b480d52a 100644 --- a/commands_test.go +++ b/commands_test.go @@ -394,4 +394,5 @@ func TestAttachDisconnect(t *testing.T) { // Try to avoid the timeoout in destroy. Best effort, don't check error cStdin, _ := container.StdinPipe() cStdin.Close() + container.Wait() } From c45beabcd54090bcb31eaa7a5af5878262b7b0e5 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 23 Apr 2013 11:22:30 -0700 Subject: [PATCH 3/4] Improve TestMultipleAttachRestart to avoid unnecessary warning --- container_test.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/container_test.go b/container_test.go index fef5331e3a..81ae883c3a 100644 --- a/container_test.go +++ b/container_test.go @@ -116,8 +116,8 @@ func TestMultipleAttachRestart(t *testing.T) { if err := container.Start(); err != nil { t.Fatal(err) } - timeout := make(chan bool) - go func() { + + setTimeout(t, "Timeout reading from the process", 3*time.Second, func() { l1, err = bufio.NewReader(stdout1).ReadString('\n') if err != nil { t.Fatal(err) @@ -139,15 +139,8 @@ func TestMultipleAttachRestart(t *testing.T) { if strings.Trim(l3, " \r\n") != "hello" { t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l3) } - timeout <- false - }() - go func() { - time.Sleep(3 * time.Second) - timeout <- true - }() - if <-timeout { - t.Fatalf("Timeout reading from the process") - } + }) + container.Wait() } func TestDiff(t *testing.T) { From 6ebb2491314afb3be4b0b82d14ddba743ec460de Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 23 Apr 2013 11:25:16 -0700 Subject: [PATCH 4/4] Remove unecessary memeory limit within tests --- container_test.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/container_test.go b/container_test.go index 81ae883c3a..b498f4f186 100644 --- a/container_test.go +++ b/container_test.go @@ -22,9 +22,8 @@ func TestIdFormat(t *testing.T) { defer nuke(runtime) container1, err := runtime.Create( &Config{ - Image: GetTestImage(runtime).Id, - Cmd: []string{"/bin/sh", "-c", "echo hello world"}, - Memory: 33554432, + Image: GetTestImage(runtime).Id, + Cmd: []string{"/bin/sh", "-c", "echo hello world"}, }, ) if err != nil { @@ -50,7 +49,6 @@ func TestMultipleAttachRestart(t *testing.T) { Image: GetTestImage(runtime).Id, Cmd: []string{"/bin/sh", "-c", "i=1; while [ $i -le 5 ]; do i=`expr $i + 1`; echo hello; done"}, - Memory: 33554432, }, ) if err != nil { @@ -227,9 +225,8 @@ func TestCommitRun(t *testing.T) { defer nuke(runtime) container1, err := runtime.Create( &Config{ - Image: GetTestImage(runtime).Id, - Cmd: []string{"/bin/sh", "-c", "echo hello > /world"}, - Memory: 33554432, + Image: GetTestImage(runtime).Id, + Cmd: []string{"/bin/sh", "-c", "echo hello > /world"}, }, ) if err != nil { @@ -260,9 +257,8 @@ func TestCommitRun(t *testing.T) { container2, err := runtime.Create( &Config{ - Image: img.Id, - Memory: 33554432, - Cmd: []string{"cat", "/world"}, + Image: img.Id, + Cmd: []string{"cat", "/world"}, }, ) if err != nil { @@ -347,9 +343,8 @@ func TestRun(t *testing.T) { defer nuke(runtime) container, err := runtime.Create( &Config{ - Image: GetTestImage(runtime).Id, - Memory: 33554432, - Cmd: []string{"ls", "-al"}, + Image: GetTestImage(runtime).Id, + Cmd: []string{"ls", "-al"}, }, ) if err != nil {