Added a test to ensure that the docker driver is removing containers after container exits successfully

This commit is contained in:
Diptanu Choudhury 2016-04-12 01:00:14 -04:00
parent 02f16e0ea5
commit e599ab795c

View file

@ -757,3 +757,47 @@ func TestDockerUser(t *testing.T) {
t.Fatalf("Expecting '%v' in '%v'", msg, err) t.Fatalf("Expecting '%v' in '%v'", msg, err)
} }
} }
func TestDockerDriver_CleanupContainer(t *testing.T) {
t.Parallel()
task := &structs.Task{
Name: "redis-demo",
Config: map[string]interface{}{
"image": "busybox",
"command": "/bin/echo",
"args": []string{"hello"},
},
Resources: &structs.Resources{
MemoryMB: 256,
CPU: 512,
},
LogConfig: &structs.LogConfig{
MaxFiles: 10,
MaxFileSizeMB: 10,
},
}
_, handle, cleanup := dockerSetup(t, task)
defer cleanup()
// Update should be a no-op
err := handle.Update(task)
if err != nil {
t.Fatalf("err: %v", err)
}
select {
case res := <-handle.WaitCh():
if !res.Successful() {
t.Fatalf("err: %v", res)
}
case <-time.After(time.Duration(tu.TestMultiplier()*5) * time.Second):
t.Fatalf("timeout")
}
// Ensure that the container isn't present
if _, err := client.InspectContainer(handle.(*DockerHandle).containerID); err == nil {
t.Fatalf("expected to not get container")
}
}