Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions daemon/mgr/container_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *Container) SetStatusStopped(exitCode int64, errMsg string) {
defer c.Unlock()
c.State.Status = types.StatusStopped
c.State.FinishedAt = time.Now().UTC().Format(utils.TimeLayout)
c.State.Pid = -1
c.State.Pid = 0
c.State.ExitCode = exitCode
c.State.Error = errMsg
c.setStatusFlags(types.StatusStopped)
Expand All @@ -117,7 +117,7 @@ func (c *Container) SetStatusExited(exitCode int64, errMsg string) {
defer c.Unlock()
c.State.Status = types.StatusExited
c.State.FinishedAt = time.Now().UTC().Format(utils.TimeLayout)
c.State.Pid = -1
c.State.Pid = 0
c.State.ExitCode = exitCode
c.State.Error = errMsg
c.setStatusFlags(types.StatusExited)
Expand Down
33 changes: 33 additions & 0 deletions test/cli_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,36 @@ func (suite *PouchStopSuite) TestStopMultiContainers(c *check.C) {
c.Assert(string(result[0].State.Status), check.Equals, "stopped")

}

// TestStopPidValue ensure stopped container's pid is 0
func (suite *PouchStopSuite) TestStopPidValue(c *check.C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add one case for the process exits by itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

name := "test-stop-pid-value"

command.PouchRun("run", "-d", "--name", name, busyboxImage, "top").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, name)

// test stop a created container
command.PouchRun("stop", name).Assert(c, icmd.Success)

output := command.PouchRun("inspect", name).Stdout()
result := []types.ContainerJSON{}
if err := json.Unmarshal([]byte(output), &result); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
c.Assert(result[0].State.Pid, check.Equals, int64(0))
}

// TestAutoStopPidValue ensure stopped container's pid is 0
func (suite *PouchStopSuite) TestAutoStopPidValue(c *check.C) {
name := "test-auto-stop-pid-value"

command.PouchRun("run", "--name", name, busyboxImage, "echo", "hi").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, name)

output := command.PouchRun("inspect", name).Stdout()
result := []types.ContainerJSON{}
if err := json.Unmarshal([]byte(output), &result); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
c.Assert(result[0].State.Pid, check.Equals, int64(0))
}