mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
prober: fix test flake
This was tested by running 10000 test iterations and observing no flakes after this change was made. Change-Id: Ib036fd03a3a17800132c53c838cc32bfe2961306 Signed-off-by: Andrew Dunham <andrew@tailscale.com>
This commit is contained in:
parent
988c1f0ac7
commit
06b55ab50f
@ -97,7 +97,7 @@ func TestProberTimingSpread(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Run("test-spread-probe", probeInterval, nil, func(context.Context) error {
|
probe := p.Run("test-spread-probe", probeInterval, nil, func(context.Context) error {
|
||||||
invoked <- struct{}{}
|
invoked <- struct{}{}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -110,6 +110,36 @@ func TestProberTimingSpread(t *testing.T) {
|
|||||||
clk.Advance(halfProbeInterval)
|
clk.Advance(halfProbeInterval)
|
||||||
called()
|
called()
|
||||||
notCalled()
|
notCalled()
|
||||||
|
|
||||||
|
// We need to wait until the main (non-initial) ticker in Probe.loop is
|
||||||
|
// waiting, or we could race and advance the test clock between when
|
||||||
|
// the initial delay ticker completes and before the ticker for the
|
||||||
|
// main loop is created. In this race, we'd first advance the test
|
||||||
|
// clock, then the ticker would be registered, and the test would fail
|
||||||
|
// because that ticker would never be fired.
|
||||||
|
err := tstest.WaitFor(convergenceTimeout, func() error {
|
||||||
|
clk.Lock()
|
||||||
|
defer clk.Unlock()
|
||||||
|
for _, tick := range clk.tickers {
|
||||||
|
tick.Lock()
|
||||||
|
stopped, interval := tick.stopped, tick.interval
|
||||||
|
tick.Unlock()
|
||||||
|
|
||||||
|
if stopped {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Test for the main loop, not the initialDelay
|
||||||
|
if interval == probe.interval {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("no ticker with interval %d found", probe.interval)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
clk.Advance(quarterProbeInterval)
|
clk.Advance(quarterProbeInterval)
|
||||||
notCalled()
|
notCalled()
|
||||||
clk.Advance(probeInterval)
|
clk.Advance(probeInterval)
|
||||||
|
Loading…
Reference in New Issue
Block a user