diff --git a/test/events/events.go b/test/events/events.go index 22e3056d10a..3a8731b29f8 100644 --- a/test/events/events.go +++ b/test/events/events.go @@ -52,39 +52,27 @@ func CheckEventsUnordered(t *testing.T, eventChan chan string, testName string, // expects to receive. The events must be received in the same order they appear in the // wantEvents list. Any extra or too few received events are considered errors. func eventsFromChannel(c chan string, wantEvents []string) error { - // We get events from a channel, so the timeout is here to avoid waiting - // on the channel forever if fewer than expected events are received. - // We only hit the timeout in case of failure of the test, so the actual value - // of the timeout is not so relevant, it's only used when tests are going to fail. - // on the channel forever if fewer than expected events are received - timer := time.NewTimer(10 * time.Millisecond) + // we loop the channel to collect all events, if the collected events are not + // expected events we will return error + foundEvents := []string{} - for ii := 0; ii < len(wantEvents)+1; ii++ { - // We loop over all the events that we expect. Once they are all received - // we exit the loop. If we never receive enough events, the timeout takes us - // out of the loop. - select { - case event := <-c: - foundEvents = append(foundEvents, event) - if ii > len(wantEvents)-1 { - return fmt.Errorf("received event \"%s\" but not more expected", event) - } - wantEvent := wantEvents[ii] - matching, err := regexp.MatchString(wantEvent, event) - if err == nil { - if !matching { - return fmt.Errorf("expected event \"%s\" but got \"%s\" instead", wantEvent, event) - } - } else { - return fmt.Errorf("something went wrong matching the event: %s", err) - } - case <-timer.C: - if len(foundEvents) != len(wantEvents) { - return fmt.Errorf("received %d events but %d expected. Found events: %#v", len(foundEvents), len(wantEvents), foundEvents) + channelEvents := len(c) + for ii := 0; ii < channelEvents; ii++ { + event := <-c + foundEvents = append(foundEvents, event) + wantEvent := wantEvents[ii] + matching, err := regexp.MatchString(wantEvent, event) + if err == nil { + if !matching { + return fmt.Errorf("expected event \"%s\" but got \"%s\" instead", wantEvent, event) } - return nil + } else { + return fmt.Errorf("something went wrong matching the event: %s", err) } } + if len(foundEvents) != len(wantEvents) { + return fmt.Errorf("received %d events but %d expected. Found events: %#v", len(foundEvents), len(wantEvents), foundEvents) + } return nil }