wip: fix TestWGEngineStatusRace

At the moment the test itself is broken, so it's hard to tell if the code under test is fixed or not. Maybe it is?
zofrex/fix-test-wg-engine-status-race
James Sanderson 2 months ago
parent 05a4c8e839
commit 0ad7d4ee40

@ -1064,13 +1064,13 @@ func (s *testStateStorage) sawWrite() bool {
} }
func TestWGEngineStatusRace(t *testing.T) { func TestWGEngineStatusRace(t *testing.T) {
t.Skip("test fails") // t.Skip("test fails")
c := qt.New(t) c := qt.New(t)
logf := tstest.WhileTestRunningLogger(t) logf := tstest.WhileTestRunningLogger(t)
sys := tsd.NewSystem() sys := tsd.NewSystem()
sys.Set(new(mem.Store)) sys.Set(new(mem.Store))
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.Bus.Get()) eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker.Get(), sys.UserMetricsRegistry(), sys.Bus.Get())
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
t.Cleanup(eng.Close) t.Cleanup(eng.Close)
sys.Set(eng) sys.Set(eng)
@ -1087,27 +1087,37 @@ func TestWGEngineStatusRace(t *testing.T) {
var state ipn.State var state ipn.State
b.SetNotifyCallback(func(n ipn.Notify) { b.SetNotifyCallback(func(n ipn.Notify) {
if n.State != nil { if n.State != nil {
t.Logf("Notify: %v", n.State)
state = *n.State state = *n.State
} }
}) })
wantState := func(want ipn.State) { wantState := func(want ipn.State) {
c.Assert(want, qt.Equals, state) t.Helper()
c.Assert(state, qt.Equals, want)
} }
// Start with the zero value. // Start with the zero value.
wantState(ipn.NoState) wantState(ipn.NoState)
// Start the backend. // Start the backend.
err = b.Start(ipn.Options{}) err = b.Start(ipn.Options{
UpdatePrefs: &ipn.Prefs{
WantRunning: true,
},
})
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
wantState(ipn.NeedsLogin) wantState(ipn.NeedsLogin)
// Assert that we are logged in and authorized. // Assert that we are logged in and authorized.
cc.persist.UserProfile.LoginName = "user1"
cc.persist.NodeID = "node1"
cc.send(nil, "", true, &netmap.NetworkMap{ cc.send(nil, "", true, &netmap.NetworkMap{
SelfNode: (&tailcfg.Node{MachineAuthorized: true}).View(), SelfNode: (&tailcfg.Node{MachineAuthorized: true}).View(),
}) })
wantState(ipn.Starting) wantState(ipn.Starting)
timestamp := time.Now()
// Simulate multiple concurrent callbacks from wgengine. // Simulate multiple concurrent callbacks from wgengine.
// Any single callback with DERPS > 0 is enough to transition // Any single callback with DERPS > 0 is enough to transition
// from Starting to Running, at which point we stay there. // from Starting to Running, at which point we stay there.
@ -1123,11 +1133,20 @@ func TestWGEngineStatusRace(t *testing.T) {
if i == 0 { if i == 0 {
n = 1 n = 1
} }
b.setWgengineStatus(&wgengine.Status{AsOf: time.Now(), DERPs: n}, nil) b.setWgengineStatus(&wgengine.Status{AsOf: timestamp, DERPs: n}, nil)
}(i) }(i)
} }
wg.Wait() wg.Wait()
wantState(ipn.Running)
err = tstest.WaitFor(100*time.Millisecond, func() error {
if state == ipn.Running {
return nil
}
return fmt.Errorf("got state = %v; want Running", state)
})
if err != nil {
t.Error(err)
}
} }
// TestEngineReconfigOnStateChange verifies that wgengine is properly reconfigured // TestEngineReconfigOnStateChange verifies that wgengine is properly reconfigured

Loading…
Cancel
Save