From 2fe2f7a1864068e7d268833bb40536064f69b8aa Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 13 May 2015 02:49:47 +0000 Subject: [PATCH] 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 --- integration-cli/docker_cli_logs_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go index 47c18322ea..663caaf7a5 100644 --- a/integration-cli/docker_cli_logs_test.go +++ b/integration-cli/docker_cli_logs_test.go @@ -281,15 +281,16 @@ func (s *DockerSuite) TestLogsFollowStopped(c *check.C) { func (s *DockerSuite) TestLogsSince(c *check.C) { 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) if err != nil { c.Fatalf("run failed with errors: %s, %v", out, err) } - outLines := strings.Split(out, "\n") - startUnix, _ := strconv.ParseInt(outLines[0], 10, 64) - since := startUnix + 3 + log2Line := strings.Split(strings.Split(out, "\n")[1], " ") + t, err := strconv.ParseInt(log2Line[0], 10, 64) // the timestamp log2 is writen + 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) out, _, err = runCommandWithOutput(logsCmd) @@ -306,7 +307,7 @@ func (s *DockerSuite) TestLogsSince(c *check.C) { } // 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{ exec.Command(dockerBinary, "logs", "-t", name), exec.Command(dockerBinary, "logs", "-t", "--since=0", name),