From 5268ba5488c5221e5d9d5cacce19cfcf7d932081 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Wed, 10 Jun 2020 10:51:39 +1200 Subject: [PATCH] Ensure events occur regardless of the events in between --- test/e2e/framework/util.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index e7a56d68e31..ec6271c2454 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -1317,22 +1317,26 @@ retriesLoop: // NOTE the test may need access to the events to see what's going on, such as a change in status actualWatchEvents := scenario(resourceWatch) errs := sets.NewString() - // watchEventsLoop: + ExpectEqual(len(expectedWatchEvents) <= len(actualWatchEvents), true, "Error: actual watch events amount (%d) must be greater than or equal to expected watch events amount (%d)", len(actualWatchEvents), len(expectedWatchEvents)) + totalValidWatchEvents := 0 - actualWatchEventsHasDelete := false - for watchEventIndex := range expectedWatchEvents { + foundEventIndexes := map[int]*int{} + + for watchEventIndex, expectedWatchEvent := range expectedWatchEvents { foundExpectedWatchEvent := false - ExpectEqual(len(expectedWatchEvents) <= len(actualWatchEvents), true, "Error: actual watch events amount (%d) must be greater than or equal to expected watch events amount (%d)", len(actualWatchEvents), len(expectedWatchEvents)) - for actualWatchEventIndex := range actualWatchEvents { - if actualWatchEvents[watchEventIndex].Type == expectedWatchEvents[actualWatchEventIndex].Type { - foundExpectedWatchEvent = true + actualWatchEventsLoop: + for actualWatchEventIndex, actualWatchEvent := range actualWatchEvents { + if foundEventIndexes[actualWatchEventIndex] != nil { + continue actualWatchEventsLoop } - if actualWatchEvents[actualWatchEventIndex].Type == watch.Deleted && actualWatchEventsHasDelete != true { - actualWatchEventsHasDelete = true + if actualWatchEvent.Type == expectedWatchEvent.Type { + foundExpectedWatchEvent = true + foundEventIndexes[actualWatchEventIndex] = &watchEventIndex + break actualWatchEventsLoop } } if foundExpectedWatchEvent == false { - errs.Insert(fmt.Sprintf("Watch event %v not found", expectedWatchEvents[watchEventIndex].Type)) + errs.Insert(fmt.Sprintf("Watch event %v not found", expectedWatchEvent.Type)) } totalValidWatchEvents++ }