Browse Source

More thorough test case, use container.Stop() instead of lxc-kill,
use setStopped() during the restore step

shin- 12 years ago
parent
commit
c780ff5ae7
2 changed files with 14 additions and 4 deletions
  1. 2 2
      runtime.go
  2. 12 2
      runtime_test.go

+ 2 - 2
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
 				}

+ 12 - 2
runtime_test.go

@@ -297,10 +297,15 @@ 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)
+	}
+
 	// 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 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++
 		}
 	}