wgengine/magicsock: fix warnings about nil health.Tracker (#20264)
Tests in magicsock_test.go would routinely emit this warning: ## WARNING: (non-fatal) nil health.Tracker (being strict in CI): because they would run NewConn without initializing a health.Tracker. This patch initializes Conn correctly with a health.Tracker. It also fixes some missing Close calls that can be handled in t.Cleanup. Fixes #20263 Signed-off-by: Simon Law <sfllaw@tailscale.com>
This commit is contained in:
@@ -443,6 +443,7 @@ func TestNewConn(t *testing.T) {
|
|||||||
Logf: t.Logf,
|
Logf: t.Logf,
|
||||||
NetMon: netMon,
|
NetMon: netMon,
|
||||||
EventBus: bus,
|
EventBus: bus,
|
||||||
|
HealthTracker: health.NewTracker(bus),
|
||||||
Metrics: new(usermetric.Registry),
|
Metrics: new(usermetric.Registry),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -678,6 +679,7 @@ func TestDeviceStartStop(t *testing.T) {
|
|||||||
Logf: t.Logf,
|
Logf: t.Logf,
|
||||||
NetMon: netMon,
|
NetMon: netMon,
|
||||||
EventBus: bus,
|
EventBus: bus,
|
||||||
|
HealthTracker: health.NewTracker(bus),
|
||||||
Metrics: new(usermetric.Registry),
|
Metrics: new(usermetric.Registry),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1553,6 +1555,7 @@ func newTestConn(t testing.TB) *Conn {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
bus := eventbustest.NewBus(t)
|
bus := eventbustest.NewBus(t)
|
||||||
|
t.Cleanup(bus.Close)
|
||||||
|
|
||||||
netMon, err := netmon.New(bus, logger.WithPrefix(t.Logf, "... netmon: "))
|
netMon, err := netmon.New(bus, logger.WithPrefix(t.Logf, "... netmon: "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1576,6 +1579,7 @@ func newTestConn(t testing.TB) *Conn {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() { conn.Close() })
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3344,10 +3348,13 @@ func TestMaybeRebindOnError(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestConnAndRegistry(t *testing.T) (*Conn, *usermetric.Registry, func()) {
|
func newTestConnAndRegistry(t *testing.T) (*Conn, *usermetric.Registry) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
bus := eventbus.New()
|
bus := eventbus.New()
|
||||||
|
t.Cleanup(bus.Close)
|
||||||
|
|
||||||
netMon := must.Get(netmon.New(bus, t.Logf))
|
netMon := must.Get(netmon.New(bus, t.Logf))
|
||||||
|
t.Cleanup(func() { netMon.Close() })
|
||||||
|
|
||||||
reg := new(usermetric.Registry)
|
reg := new(usermetric.Registry)
|
||||||
|
|
||||||
@@ -3356,14 +3363,12 @@ func newTestConnAndRegistry(t *testing.T) (*Conn, *usermetric.Registry, func())
|
|||||||
Logf: t.Logf,
|
Logf: t.Logf,
|
||||||
NetMon: netMon,
|
NetMon: netMon,
|
||||||
EventBus: bus,
|
EventBus: bus,
|
||||||
|
HealthTracker: health.NewTracker(bus),
|
||||||
Metrics: reg,
|
Metrics: reg,
|
||||||
}))
|
}))
|
||||||
|
t.Cleanup(func() { conn.Close() })
|
||||||
|
|
||||||
return conn, reg, func() {
|
return conn, reg
|
||||||
bus.Close()
|
|
||||||
netMon.Close()
|
|
||||||
conn.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetworkSendErrors(t *testing.T) {
|
func TestNetworkSendErrors(t *testing.T) {
|
||||||
@@ -3383,8 +3388,7 @@ func TestNetworkSendErrors(t *testing.T) {
|
|||||||
|
|
||||||
tstest.Replace(t, &checkNetworkDownDuringTests, true)
|
tstest.Replace(t, &checkNetworkDownDuringTests, true)
|
||||||
|
|
||||||
conn, reg, close := newTestConnAndRegistry(t)
|
conn, reg := newTestConnAndRegistry(t)
|
||||||
defer close()
|
|
||||||
|
|
||||||
buffs := [][]byte{{00, 00, 00, 00, 00, 00, 00, 00}}
|
buffs := [][]byte{{00, 00, 00, 00, 00, 00, 00, 00}}
|
||||||
ep := &lazyEndpoint{
|
ep := &lazyEndpoint{
|
||||||
@@ -3413,8 +3417,7 @@ func TestNetworkSendErrors(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid-payload", func(t *testing.T) {
|
t.Run("invalid-payload", func(t *testing.T) {
|
||||||
conn, reg, close := newTestConnAndRegistry(t)
|
conn, reg := newTestConnAndRegistry(t)
|
||||||
defer close()
|
|
||||||
|
|
||||||
conn.SetNetworkUp(false)
|
conn.SetNetworkUp(false)
|
||||||
err := conn.Send([][]byte{{00}}, &lazyEndpoint{}, 0)
|
err := conn.Send([][]byte{{00}}, &lazyEndpoint{}, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user