From ebba0a60245b487e6d3d242f47c8999321ec5d29 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 2 Jul 2013 10:47:37 +0000 Subject: [PATCH] add sleep in tests and go fmt --- buildfile_test.go | 6 +++--- container_test.go | 5 ++++- runtime_test.go | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/buildfile_test.go b/buildfile_test.go index 0895cccc80..8dc0410623 100644 --- a/buildfile_test.go +++ b/buildfile_test.go @@ -1,10 +1,10 @@ package docker import ( + "fmt" "io/ioutil" "sync" "testing" - "fmt" ) // mkTestContext generates a build context from the contents of the provided dockerfile. @@ -104,8 +104,8 @@ func TestBuild(t *testing.T) { defer nuke(runtime) srv := &Server{ - runtime: runtime, - lock: &sync.Mutex{}, + runtime: runtime, + lock: &sync.Mutex{}, pullingPool: make(map[string]struct{}), pushingPool: make(map[string]struct{}), } diff --git a/container_test.go b/container_test.go index 43e5093d20..7646bb3793 100644 --- a/container_test.go +++ b/container_test.go @@ -511,12 +511,15 @@ func TestKillDifferentUser(t *testing.T) { t.Fatal(err) } - setTimeout(t, "Waiting for the container to be started timed out", 2 * time.Second, func() { + setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() { for !container.State.Running { time.Sleep(10 * time.Millisecond) } }) + // Even if the state is running, lets give some time to lxc to spawn the process + container.WaitTimeout(500 * time.Millisecond) + if err := container.Kill(); err != nil { t.Fatal(err) } diff --git a/runtime_test.go b/runtime_test.go index 5ad1208f47..c367ecd4c5 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -366,14 +366,14 @@ func TestAllocatePortLocalhost(t *testing.T) { defer container.Kill() setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() { - for { - if container.State.Running { - break - } + for !container.State.Running { time.Sleep(10 * time.Millisecond) } }) + // Even if the state is running, lets give some time to lxc to spawn the process + container.WaitTimeout(500 * time.Millisecond) + conn, err := net.Dial("tcp", fmt.Sprintf( "localhost:%s", container.NetworkSettings.PortMapping[strconv.Itoa(port)],