util/eventbus/eventbustest: add support for synctest instead of timers (#17522)
Before synctest, timers was needed to allow the events to flow into the test bus. There is still a timer, but this one is not derived from the test deadline and it is mostly arbitrary as synctest will render it practically non-existent. With this approach, tests that do not need to test for the absence of events do not rely on synctest. Updates #15160 Signed-off-by: Claus Lensbøl <claus@tailscale.com>
This commit is contained in:
@@ -39,6 +39,20 @@
|
||||
// checks that the stream contains exactly the given events in the given order,
|
||||
// and no others.
|
||||
//
|
||||
// To test for the absence of events, use [ExpectExactly] without any
|
||||
// expected events, along side [testing/synctest] to avoid waiting for timers
|
||||
// to ensure that no events are produced. This will look like:
|
||||
//
|
||||
// synctest.Test(t, func(t *testing.T) {
|
||||
// bus := eventbustest.NewBus(t)
|
||||
// tw := eventbustest.NewWatcher(t, bus)
|
||||
// somethingThatShouldNotEmitsSomeEvent()
|
||||
// synctest.Wait()
|
||||
// if err := eventbustest.ExpectExactly(tw); err != nil {
|
||||
// t.Errorf("Expected no events or errors, got %v", err)
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// See the [usage examples].
|
||||
//
|
||||
// [usage examples]: https://github.com/tailscale/tailscale/blob/main/util/eventbus/eventbustest/examples_test.go
|
||||
|
||||
Reference in New Issue
Block a user