summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorM. J. Fromberger <fromberger@tailscale.com>2026-04-23 08:08:27 -0700
committerM. J. Fromberger <fromberger@tailscale.com>2026-04-24 08:25:04 -0700
commit00b32ab4ef3616aa51581d5fbd485e934f1b5696 (patch)
tree1000a106f4523ce5a70bb21cb40ae88bd10db9c3
parentad9e6c19257a13fd619fbbd07468830925c8e520 (diff)
downloadtailscale-mjf/exactitude.tar.xz
tailscale-mjf/exactitude.zip
util/eventbus: check for extra events in a test streammjf/exactitude
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>
-rw-r--r--util/eventbus/eventbustest/eventbustest.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/util/eventbus/eventbustest/eventbustest.go b/util/eventbus/eventbustest/eventbustest.go
index b3ef6c884..62fee1041 100644
--- a/util/eventbus/eventbustest/eventbustest.go
+++ b/util/eventbus/eventbustest/eventbustest.go
@@ -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
}