Browse code

integration-cli: try to make TestEventsTimestampFormats less flaky

Fix #21749

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2016/04/05 02:13:10
Showing 1 changed files
... ...
@@ -18,14 +18,13 @@ import (
18 18
 )
19 19
 
20 20
 func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
21
-	image := "busybox"
21
+	name := "events-time-format-test"
22 22
 
23 23
 	// Start stopwatch, generate an event
24
-	time.Sleep(1 * time.Second) // so that we don't grab events from previous test occurred in the same second
25 24
 	start := daemonTime(c)
26
-	dockerCmd(c, "tag", image, "timestamptest:1")
27
-	dockerCmd(c, "rmi", "timestamptest:1")
28
-	time.Sleep(1 * time.Second) // so that until > since
25
+	time.Sleep(1100 * time.Millisecond) // so that first event occur in different second from since (just for the case)
26
+	dockerCmd(c, "run", "--rm", "--name", name, "busybox", "true")
27
+	time.Sleep(1100 * time.Millisecond) // so that until > since
29 28
 	end := daemonTime(c)
30 29
 
31 30
 	// List of available time formats to --since
... ...
@@ -37,9 +36,19 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
37 37
 	for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} {
38 38
 		since, until := f(start), f(end)
39 39
 		out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until)
40
-		events := strings.Split(strings.TrimSpace(out), "\n")
41
-		c.Assert(events, checker.HasLen, 2, check.Commentf("unexpected events, was expecting only 2 events tag/untag (since=%s, until=%s) out=%s", since, until, out))
42
-		c.Assert(out, checker.Contains, "untag", check.Commentf("expected 'untag' event not found (since=%s, until=%s)", since, until))
40
+		events := strings.Split(out, "\n")
41
+		events = events[:len(events)-1]
42
+
43
+		nEvents := len(events)
44
+		c.Assert(nEvents, checker.GreaterOrEqualThan, 5) //Missing expected event
45
+		containerEvents := eventActionsByIDAndType(c, events, name, "container")
46
+		c.Assert(containerEvents, checker.HasLen, 5, check.Commentf("events: %v", events))
47
+
48
+		c.Assert(containerEvents[0], checker.Equals, "create", check.Commentf(out))
49
+		c.Assert(containerEvents[1], checker.Equals, "attach", check.Commentf(out))
50
+		c.Assert(containerEvents[2], checker.Equals, "start", check.Commentf(out))
51
+		c.Assert(containerEvents[3], checker.Equals, "die", check.Commentf(out))
52
+		c.Assert(containerEvents[4], checker.Equals, "destroy", check.Commentf(out))
43 53
 	}
44 54
 
45 55
 }