From 94c2057effd0a3b7bfc91a5b4299bbafb405a77e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 20 Sep 2013 13:36:19 -0700 Subject: [PATCH] Improve detach unit tests Upstream-commit: e97364ecd73fac7abfbd82cc7e3ebaa6cda3c935 Component: engine --- components/engine/commands_test.go | 12 +++++++++++- components/engine/container.go | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/components/engine/commands_test.go b/components/engine/commands_test.go index 7b94c30b3a..dbd85be0c7 100644 --- a/components/engine/commands_test.go +++ b/components/engine/commands_test.go @@ -404,7 +404,12 @@ func TestRunDetach(t *testing.T) { <-ch }) - setTimeout(t, "Waiting for container to die timedout", 5*time.Second, func() { + time.Sleep(500 * time.Millisecond) + if !container.State.Running { + t.Fatal("The detached container should be still running") + } + + setTimeout(t, "Waiting for container to die timed out", 20*time.Second, func() { container.Kill() container.Wait() }) @@ -457,6 +462,11 @@ func TestAttachDetach(t *testing.T) { <-ch }) + time.Sleep(500 * time.Millisecond) + if !container.State.Running { + t.Fatal("The detached container should be still running") + } + setTimeout(t, "Waiting for container to die timedout", 5*time.Second, func() { container.Kill() container.Wait() diff --git a/components/engine/container.go b/components/engine/container.go index fd158afb70..aa0b586870 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -957,9 +957,6 @@ func (container *Container) monitor() { } utils.Debugf("Process finished") - if container.runtime != nil && container.runtime.srv != nil { - container.runtime.srv.LogEvent("die", container.ShortID(), container.runtime.repositories.ImageName(container.Image)) - } exitCode := -1 if container.cmd != nil { exitCode = container.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() @@ -968,6 +965,10 @@ func (container *Container) monitor() { // Report status back container.State.setStopped(exitCode) + if container.runtime != nil && container.runtime.srv != nil { + container.runtime.srv.LogEvent("die", container.ShortID(), container.runtime.repositories.ImageName(container.Image)) + } + // Cleanup container.releaseNetwork() if container.Config.OpenStdin {