From ebcce18d96d06feb5a28914c84c56eb72a8c7f0e Mon Sep 17 00:00:00 2001 From: Janet Kuo Date: Tue, 23 Feb 2016 16:39:29 -0800 Subject: [PATCH] Sort events by their first timestamp when dumping them --- test/e2e/util.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/test/e2e/util.go b/test/e2e/util.go index 849ef8bd81d..2d1c282521b 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -28,6 +28,7 @@ import ( "os" "os/exec" "path/filepath" + "sort" "strconv" "strings" "sync" @@ -1828,8 +1829,13 @@ func dumpAllNamespaceInfo(c *client.Client, namespace string) { events, err := c.Events(namespace).List(api.ListOptions{}) Expect(err).NotTo(HaveOccurred()) - for _, e := range events.Items { - Logf("event for %v: %v %v: %v", e.InvolvedObject.Name, e.Source, e.Reason, e.Message) + // Sort events by their first timestamp + sortedEvents := events.Items + if len(sortedEvents) > 1 { + sort.Sort(byFirstTimestamp(sortedEvents)) + } + for _, e := range sortedEvents { + Logf("At %v - event for %v: %v %v: %v", e.FirstTimestamp, e.InvolvedObject.Name, e.Source, e.Reason, e.Message) } // Note that we don't wait for any cleanup to propagate, which means // that if you delete a bunch of pods right before ending your test, @@ -1840,6 +1846,19 @@ func dumpAllNamespaceInfo(c *client.Client, namespace string) { dumpAllNodeInfo(c) } +// byFirstTimestamp sorts a slice of events by first timestamp, using their involvedObject's name as a tie breaker. +type byFirstTimestamp []api.Event + +func (o byFirstTimestamp) Len() int { return len(o) } +func (o byFirstTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] } + +func (o byFirstTimestamp) Less(i, j int) bool { + if o[i].FirstTimestamp.Equal(o[j].FirstTimestamp) { + return o[i].InvolvedObject.Name < o[j].InvolvedObject.Name + } + return o[i].FirstTimestamp.Before(o[j].FirstTimestamp) +} + func dumpAllPodInfo(c *client.Client) { pods, err := c.Pods("").List(api.ListOptions{}) if err != nil {