mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-27 11:41:14 +00:00
ipn/ipnlocal: fail test if more notifies are put than expected
The `put` callback runs on a different goroutine to the test, so calling t.Fatalf in put had no effect. `drain` is always called when checking what was put and is called from the test goroutine, so that's a good place to fail the test if the channel was too full. Updates #17363 Signed-off-by: James Sanderson <jsanderson@tailscale.com>
This commit is contained in:
committed by
James 'zofrex' Sanderson
parent
af1114e896
commit
ebc370e517
@@ -59,8 +59,9 @@ type notifyThrottler struct {
|
|||||||
|
|
||||||
// ch gets replaced frequently. Lock the mutex before getting or
|
// ch gets replaced frequently. Lock the mutex before getting or
|
||||||
// setting it, but not while waiting on it.
|
// setting it, but not while waiting on it.
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
ch chan ipn.Notify
|
ch chan ipn.Notify
|
||||||
|
putErr error // set by put if the channel is full
|
||||||
}
|
}
|
||||||
|
|
||||||
// expect tells the throttler to expect count upcoming notifications.
|
// expect tells the throttler to expect count upcoming notifications.
|
||||||
@@ -81,7 +82,11 @@ func (nt *notifyThrottler) put(n ipn.Notify) {
|
|||||||
case ch <- n:
|
case ch <- n:
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
nt.t.Fatalf("put: channel full: %v", n)
|
err := fmt.Errorf("put: channel full: %v", n)
|
||||||
|
nt.t.Log(err)
|
||||||
|
nt.mu.Lock()
|
||||||
|
nt.putErr = err
|
||||||
|
nt.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,8 +96,13 @@ func (nt *notifyThrottler) drain(count int) []ipn.Notify {
|
|||||||
nt.t.Helper()
|
nt.t.Helper()
|
||||||
nt.mu.Lock()
|
nt.mu.Lock()
|
||||||
ch := nt.ch
|
ch := nt.ch
|
||||||
|
putErr := nt.putErr
|
||||||
nt.mu.Unlock()
|
nt.mu.Unlock()
|
||||||
|
|
||||||
|
if putErr != nil {
|
||||||
|
nt.t.Fatalf("drain: previous call to put errored: %s", putErr)
|
||||||
|
}
|
||||||
|
|
||||||
nn := []ipn.Notify{}
|
nn := []ipn.Notify{}
|
||||||
for i := range count {
|
for i := range count {
|
||||||
select {
|
select {
|
||||||
|
|||||||
Reference in New Issue
Block a user