mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-05 04:06:35 +02:00
util/eventbus: check for extra events in a test stream
In ExpectExacty, we were correctly checking that there are no further events when no filters are provided, but were not checking after a non-empty filter list that there are no additional events. Move the check after the filter loop, so we get both. Change-Id: I5c92ac510fce029421d712d7c312545ebe1a63fe Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
parent
ad9e6c1925
commit
00b32ab4ef
@ -119,14 +119,6 @@ func Expect(tw *Watcher, filters ...any) error {
|
||||
// you are testing for the absence of events, call [synctest.Wait] after
|
||||
// actions that would publish an event, but before calling ExpectExactly.
|
||||
func ExpectExactly(tw *Watcher, filters ...any) error {
|
||||
if len(filters) == 0 {
|
||||
select {
|
||||
case event := <-tw.events:
|
||||
return fmt.Errorf("saw event type %s, expected none", reflect.TypeOf(event))
|
||||
case <-time.After(100 * time.Second): // "indefinitely", to advance a synctest clock
|
||||
return nil
|
||||
}
|
||||
}
|
||||
eventCount := 0
|
||||
for pos, next := range filters {
|
||||
eventFunc := eventFilter(next)
|
||||
@ -154,6 +146,12 @@ func ExpectExactly(tw *Watcher, filters ...any) error {
|
||||
return errors.New("watcher closed while waiting for events")
|
||||
}
|
||||
}
|
||||
select {
|
||||
case event := <-tw.events:
|
||||
return fmt.Errorf("saw event type %s at index %d, expected none", reflect.TypeOf(event), eventCount)
|
||||
case <-time.After(100 * time.Second): // "indefinitely", to advance a synctest clock
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user