Skip to content

Commit

Permalink
Remove unnecessary channels under synctest
Browse files Browse the repository at this point in the history
With blocking sends on notify, we can guarantee the handler is in flight
(and durably blocked) with synctest.Wait alone.
  • Loading branch information
ahamlinman committed Feb 6, 2025
1 parent 048d56d commit 966e7d7
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions internal/watch/watch_synctest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ func TestCancelInactiveHandlerSynctest(t *testing.T) {
// The usual case of canceling a watch, where no handler is active at the time
// of cancellation.
synctest.Run(func() {
notify := make(chan string)
v := NewValue("alice")
notify := make(chan string, 1)
w := v.Watch(func(x string) {
select {
case notify <- x:
default:
}
})
w := v.Watch(func(x string) { notify <- x })

// Deal with the initial notification. Then, wait for the handler goroutine
// to exit before canceling the watch.
Expand Down Expand Up @@ -59,16 +54,12 @@ func TestWaitSynctest(t *testing.T) {
// A specific test to ensure that Wait properly blocks until the watch has
// terminated.
synctest.Run(func() {
notify := make(chan string)
v := NewValue("alice")
w := v.Watch(func(x string) { notify <- x })

block, notify := make(chan struct{}), make(chan string)
w := v.Watch(func(x string) {
<-block
notify <- x
})

// Ensure that we have a handler in flight.
block <- struct{}{}
// Ensure that we have a handler in flight from the initial notification.
synctest.Wait()

// Start waiting in the background. We should remain blocked.
done := make(chan struct{})
Expand Down

0 comments on commit 966e7d7

Please sign in to comment.