Browse code

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>

Ahmet Alp Balkan authored on 2015/05/13 11:49:47
Showing 1 changed files
... ...
@@ -281,15 +281,16 @@ func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
281 281
 
282 282
 func (s *DockerSuite) TestLogsSince(c *check.C) {
283 283
 	name := "testlogssince"
284
-	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`)
284
+	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")
285 285
 	out, _, err := runCommandWithOutput(runCmd)
286 286
 	if err != nil {
287 287
 		c.Fatalf("run failed with errors: %s, %v", out, err)
288 288
 	}
289 289
 
290
-	outLines := strings.Split(out, "\n")
291
-	startUnix, _ := strconv.ParseInt(outLines[0], 10, 64)
292
-	since := startUnix + 3
290
+	log2Line := strings.Split(strings.Split(out, "\n")[1], " ")
291
+	t, err := strconv.ParseInt(log2Line[0], 10, 64) // the timestamp log2 is writen
292
+	c.Assert(err, check.IsNil)
293
+	since := t + 1 // add 1s so log1 & log2 doesn't show up
293 294
 	logsCmd := exec.Command(dockerBinary, "logs", "-t", fmt.Sprintf("--since=%v", since), name)
294 295
 
295 296
 	out, _, err = runCommandWithOutput(logsCmd)
... ...
@@ -306,7 +307,7 @@ func (s *DockerSuite) TestLogsSince(c *check.C) {
306 306
 	}
307 307
 
308 308
 	// Test with default value specified and parameter omitted
309
-	expected := []string{"log1", "log2", "log3", "log4", "log5"}
309
+	expected := []string{"log1", "log2", "log3"}
310 310
 	for _, cmd := range []*exec.Cmd{
311 311
 		exec.Command(dockerBinary, "logs", "-t", name),
312 312
 		exec.Command(dockerBinary, "logs", "-t", "--since=0", name),