mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
integ-cli: Fix race in TestLogsSince
TestLogsSince used to rely on time synchronization and precision of the timestamps. This change provides a less flaky alternative. Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
parent
36d995a291
commit
2fe2f7a186
1 changed files with 6 additions and 5 deletions
|
@ -281,15 +281,16 @@ func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestLogsSince(c *check.C) {
|
func (s *DockerSuite) TestLogsSince(c *check.C) {
|
||||||
name := "testlogssince"
|
name := "testlogssince"
|
||||||
runCmd := exec.Command(dockerBinary, "run", "--name="+name, "busybox", "/bin/sh", "-c", `date +%s; for i in $(seq 1 5); do sleep 1; echo log$i; done`)
|
runCmd := exec.Command(dockerBinary, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo `date +%s` log$i; done")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatalf("run failed with errors: %s, %v", out, err)
|
c.Fatalf("run failed with errors: %s, %v", out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
outLines := strings.Split(out, "\n")
|
log2Line := strings.Split(strings.Split(out, "\n")[1], " ")
|
||||||
startUnix, _ := strconv.ParseInt(outLines[0], 10, 64)
|
t, err := strconv.ParseInt(log2Line[0], 10, 64) // the timestamp log2 is writen
|
||||||
since := startUnix + 3
|
c.Assert(err, check.IsNil)
|
||||||
|
since := t + 1 // add 1s so log1 & log2 doesn't show up
|
||||||
logsCmd := exec.Command(dockerBinary, "logs", "-t", fmt.Sprintf("--since=%v", since), name)
|
logsCmd := exec.Command(dockerBinary, "logs", "-t", fmt.Sprintf("--since=%v", since), name)
|
||||||
|
|
||||||
out, _, err = runCommandWithOutput(logsCmd)
|
out, _, err = runCommandWithOutput(logsCmd)
|
||||||
|
@ -306,7 +307,7 @@ func (s *DockerSuite) TestLogsSince(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test with default value specified and parameter omitted
|
// Test with default value specified and parameter omitted
|
||||||
expected := []string{"log1", "log2", "log3", "log4", "log5"}
|
expected := []string{"log1", "log2", "log3"}
|
||||||
for _, cmd := range []*exec.Cmd{
|
for _, cmd := range []*exec.Cmd{
|
||||||
exec.Command(dockerBinary, "logs", "-t", name),
|
exec.Command(dockerBinary, "logs", "-t", name),
|
||||||
exec.Command(dockerBinary, "logs", "-t", "--since=0", name),
|
exec.Command(dockerBinary, "logs", "-t", "--since=0", name),
|
||||||
|
|
Loading…
Reference in a new issue