Sort output of docker ps --filter with order by creation time
This fix tries to address the issue raised in 25374 where the output of `docker ps --filter` is in random order and not deterministic. This fix sorts the list of containers by creation time so that the output is deterministic. An integration test has been added. This fix fixes 25374. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> Upstream-commit: 3f971335463b99a7caedcf597ffc544845b37a21 Component: engine
This commit is contained in:
@ -864,3 +864,37 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
||||
|
||||
c.Assert(containerOut, checker.Contains, "onbridgenetwork")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsByOrder(c *check.C) {
|
||||
name1 := "xyz-abc"
|
||||
out, err := runSleepingContainer(c, "--name", name1)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
container1 := strings.TrimSpace(out)
|
||||
|
||||
name2 := "xyz-123"
|
||||
out, err = runSleepingContainer(c, "--name", name2)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
container2 := strings.TrimSpace(out)
|
||||
|
||||
name3 := "789-abc"
|
||||
out, err = runSleepingContainer(c, "--name", name3)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
|
||||
name4 := "789-123"
|
||||
out, err = runSleepingContainer(c, "--name", name4)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
|
||||
// Run multiple time should have the same result
|
||||
out, err = dockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz")
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1))
|
||||
|
||||
// Run multiple time should have the same result
|
||||
out, err = dockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz")
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user