mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 18:57:35 +00:00
ipn/ipnlocal: deflake (mostly) TestStateMachine
I'm sick of this flaking. Even if this isn't the right fix, it stops the alert fatigue. Updates #3020 Change-Id: I4001c127d78f1056302f7741adec34210a72ee61 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
6590fc3a94
commit
aac974a5e5
@ -87,8 +87,9 @@ func (nt *notifyThrottler) drain(count int) []ipn.Notify {
|
|||||||
type mockControl struct {
|
type mockControl struct {
|
||||||
tb testing.TB
|
tb testing.TB
|
||||||
opts controlclient.Options
|
opts controlclient.Options
|
||||||
logf logger.Logf
|
logfActual logger.Logf
|
||||||
statusFunc func(controlclient.Status)
|
statusFunc func(controlclient.Status)
|
||||||
|
preventLog syncs.AtomicBool
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
calls []string
|
calls []string
|
||||||
@ -104,6 +105,13 @@ func newMockControl(tb testing.TB) *mockControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cc *mockControl) logf(format string, args ...interface{}) {
|
||||||
|
if cc.preventLog.Get() || cc.logfActual == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cc.logfActual(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
func (cc *mockControl) SetStatusFunc(fn func(controlclient.Status)) {
|
func (cc *mockControl) SetStatusFunc(fn func(controlclient.Status)) {
|
||||||
cc.statusFunc = fn
|
cc.statusFunc = fn
|
||||||
}
|
}
|
||||||
@ -284,6 +292,7 @@ func TestStateMachine(t *testing.T) {
|
|||||||
t.Cleanup(e.Close)
|
t.Cleanup(e.Close)
|
||||||
|
|
||||||
cc := newMockControl(t)
|
cc := newMockControl(t)
|
||||||
|
t.Cleanup(func() { cc.preventLog.Set(true) }) // hacky way to pacify issue 3020
|
||||||
b, err := NewLocalBackend(logf, "logid", store, nil, e)
|
b, err := NewLocalBackend(logf, "logid", store, nil, e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("NewLocalBackend: %v", err)
|
t.Fatalf("NewLocalBackend: %v", err)
|
||||||
@ -291,7 +300,7 @@ func TestStateMachine(t *testing.T) {
|
|||||||
b.SetControlClientGetterForTesting(func(opts controlclient.Options) (controlclient.Client, error) {
|
b.SetControlClientGetterForTesting(func(opts controlclient.Options) (controlclient.Client, error) {
|
||||||
cc.mu.Lock()
|
cc.mu.Lock()
|
||||||
cc.opts = opts
|
cc.opts = opts
|
||||||
cc.logf = opts.Logf
|
cc.logfActual = opts.Logf
|
||||||
cc.authBlocked = true
|
cc.authBlocked = true
|
||||||
cc.persist = cc.opts.Persist
|
cc.persist = cc.opts.Persist
|
||||||
cc.mu.Unlock()
|
cc.mu.Unlock()
|
||||||
@ -305,6 +314,9 @@ func TestStateMachine(t *testing.T) {
|
|||||||
notifies.expect(0)
|
notifies.expect(0)
|
||||||
|
|
||||||
b.SetNotifyCallback(func(n ipn.Notify) {
|
b.SetNotifyCallback(func(n ipn.Notify) {
|
||||||
|
if cc.preventLog.Get() {
|
||||||
|
return
|
||||||
|
}
|
||||||
if n.State != nil ||
|
if n.State != nil ||
|
||||||
n.Prefs != nil ||
|
n.Prefs != nil ||
|
||||||
n.BrowseToURL != nil ||
|
n.BrowseToURL != nil ||
|
||||||
@ -315,6 +327,7 @@ func TestStateMachine(t *testing.T) {
|
|||||||
logf("\n(ignored) %v\n\n", n)
|
logf("\n(ignored) %v\n\n", n)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
t.Cleanup(func() { b.SetNotifyCallback(nil) }) // hacky way to pacify issue 3020
|
||||||
|
|
||||||
// Check that it hasn't called us right away.
|
// Check that it hasn't called us right away.
|
||||||
// The state machine should be idle until we call Start().
|
// The state machine should be idle until we call Start().
|
||||||
@ -948,7 +961,7 @@ func TestWGEngineStatusRace(t *testing.T) {
|
|||||||
b.SetControlClientGetterForTesting(func(opts controlclient.Options) (controlclient.Client, error) {
|
b.SetControlClientGetterForTesting(func(opts controlclient.Options) (controlclient.Client, error) {
|
||||||
cc.mu.Lock()
|
cc.mu.Lock()
|
||||||
defer cc.mu.Unlock()
|
defer cc.mu.Unlock()
|
||||||
cc.logf = opts.Logf
|
cc.logfActual = opts.Logf
|
||||||
return cc, nil
|
return cc, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user