From c780ff5ae726bc8acd30b9ef476cd111c477ec35 Mon Sep 17 00:00:00 2001 From: shin- Date: Tue, 2 Apr 2013 07:01:43 -0700 Subject: [PATCH] More thorough test case, use container.Stop() instead of lxc-kill, use setStopped() during the restore step --- runtime.go | 4 ++-- runtime_test.go | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/runtime.go b/runtime.go index 4f3c0a6237..9f571cf45a 100644 --- a/runtime.go +++ b/runtime.go @@ -136,14 +136,14 @@ func (runtime *Runtime) Register(container *Container) error { } // FIXME: if the container is supposed to be running but is not, auto restart it? - // If the container is supposed to be running, make sure of if + // If the container is supposed to be running, make sure of it if container.State.Running { if output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput(); err != nil { return err } else { if !strings.Contains(string(output), "RUNNING") { Debugf("Container %s was supposed to be running be is not.", container.Id) - container.State.Running = false + container.State.setStopped(-127) if err := container.ToDisk(); err != nil { return err } diff --git a/runtime_test.go b/runtime_test.go index 604f4aac38..4f6ddd1d41 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -297,10 +297,15 @@ func TestRestore(t *testing.T) { t.Fatal(err) } - // Simulate a crash/manual quit of dockerd: process dies, states stays 'Running' - if err := exec.Command("lxc-kill", "-n", container1_1.Id, "9").Run(); err == nil { - t.Fatalf("container supposed to be killed (return error 255). Success received.") + if !container1_1.State.Running { + t.Fatalf("Container %v should appear as running but isn't", container1_1.Id) } + + // Simulate a crash/manual quit of dockerd: process dies, states stays 'Running' + if err := container1_1.Stop(); err != nil { + t.Fatalf("Could not stop container: %v", err) + } + container1_1.State.Running = true if len(runtime1.List()) != 2 { @@ -310,6 +315,10 @@ func TestRestore(t *testing.T) { t.Fatal(err) } + if !container1_1.State.Running { + t.Fatalf("Container %v should appear as running but isn't", container1_1.Id) + } + // Here are are simulating a docker restart - that is, reloading all containers // from scratch runtime2, err := NewRuntimeFromDirectory(root) @@ -323,6 +332,7 @@ func TestRestore(t *testing.T) { runningCount := 0 for _, c := range runtime2.List() { if c.State.Running { + t.Errorf("Running container found: %v (%v)", c.Id, c.Path) runningCount++ } }