Skip to content

Commit

Permalink
check if event already exists before adding them
Browse files Browse the repository at this point in the history
Sometimes the same events are generated multiple times and lately its causing
very frequent build system failures. This is an attempt to unblock PR reviews
until we fix it the right way (not generating duplicate events).
  • Loading branch information
pritidesai committed Jun 24, 2020
1 parent c944643 commit 7c6c72f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestPipelineRun(t *testing.T) {
collectedEvents += ", "
}
}
t.Fatalf("Expected %d number of successful events from pipelinerun and taskrun but got %d; list of receieved events : %#v", td.expectedNumberOfEvents, len(events), collectedEvents)
t.Fatalf("Expected %d number of successful events from pipelinerun and taskrun but got %d; list of received events : %#v", td.expectedNumberOfEvents, len(events), collectedEvents)
}

// Wait for up to 10 minutes and restart every second to check if
Expand Down Expand Up @@ -550,6 +550,16 @@ func getName(namespace string, suffix int) string {
return fmt.Sprintf("%s%d", namespace, suffix)
}

// inEvents returns true if the specified event already exists in the list of specified events
func inEvents(events []*corev1.Event, event *corev1.Event) bool {
for _, e := range events {
if event.InvolvedObject.Name == e.InvolvedObject.Name && event.Reason == e.Reason {
return true
}
}
return false
}

// collectMatchingEvents collects list of events under 5 seconds that match
// 1. matchKinds which is a map of Kind of Object with name of objects
// 2. reason which is the expected reason of event
Expand All @@ -573,7 +583,9 @@ func collectMatchingEvents(kubeClient *knativetest.KubeClient, namespace string,
if val, ok := kinds[event.InvolvedObject.Kind]; ok {
for _, expectedName := range val {
if event.InvolvedObject.Name == expectedName && event.Reason == reason {
events = append(events, event)
if !inEvents(events, event) {
events = append(events, event)
}
}
}
}
Expand Down

0 comments on commit 7c6c72f

Please sign in to comment.