1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add a check to avoid double start (resulting in dockerd to panic) and unit test for it

This commit is contained in:
Guillaume J. Charmes 2013-03-31 14:15:10 -07:00
parent a6779bcae2
commit d949e2804a
2 changed files with 37 additions and 0 deletions

View file

@ -230,6 +230,9 @@ func (container *Container) start() error {
} }
func (container *Container) Start() error { func (container *Container) Start() error {
if container.State.Running {
return fmt.Errorf("The container %s is already running.", container.Id)
}
if err := container.EnsureMounted(); err != nil { if err := container.EnsureMounted(); err != nil {
return err return err
} }

View file

@ -231,6 +231,40 @@ func TestCommitRun(t *testing.T) {
} }
} }
func TestStart(t *testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
container, err := runtime.Create(
&Config{
Image: GetTestImage(runtime).Id,
Memory: 33554432,
Cmd: []string{"/bin/cat"},
OpenStdin: true,
},
)
if err != nil {
t.Fatal(err)
}
defer runtime.Destroy(container)
if err := container.Start(); err != nil {
t.Fatal(err)
}
// Give some time to the process to start
container.WaitTimeout(500 * time.Millisecond)
if !container.State.Running {
t.Errorf("Container should be running")
}
if err := container.Start(); err == nil {
t.Fatalf("A running containter should be able to be started")
}
}
func TestRun(t *testing.T) { func TestRun(t *testing.T) {
runtime, err := newTestRuntime() runtime, err := newTestRuntime()
if err != nil { if err != nil {