Ensure events occur regardless of the events in between

This commit is contained in:
Caleb Woodbine 2020-06-10 10:51:39 +12:00
parent 39fd803140
commit 5268ba5488

View File

@ -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:
totalValidWatchEvents := 0
actualWatchEventsHasDelete := false
for watchEventIndex := 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
totalValidWatchEvents := 0
foundEventIndexes := map[int]*int{}
for watchEventIndex, expectedWatchEvent := range expectedWatchEvents {
foundExpectedWatchEvent := false
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++
}