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:
M. J. Fromberger 2026-04-23 08:08:27 -07:00
parent ad9e6c1925
commit 00b32ab4ef

View File

@ -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
}