From 82454b57dd5672047c950a8299d4025c9b29e7a5 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Fri, 4 Aug 2023 14:55:05 -0600 Subject: [PATCH] ipn/ipnlocal: make tests pass when offline Updates #cleanup Signed-off-by: Maisem Ali --- ipn/ipnlocal/local.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index c8ca64058..43619a62a 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -8,6 +8,7 @@ import ( "encoding/base64" "encoding/json" "errors" + "flag" "fmt" "io" "log" @@ -64,6 +65,7 @@ import ( "tailscale.com/types/dnstype" "tailscale.com/types/empty" "tailscale.com/types/key" + "tailscale.com/types/lazy" "tailscale.com/types/logger" "tailscale.com/types/logid" "tailscale.com/types/netmap" @@ -91,6 +93,14 @@ import ( "tailscale.com/wgengine/wgcfg/nmcfg" ) +var lazyInTest lazy.SyncValue[bool] + +func inTest() bool { + return lazyInTest.Get(func() bool { + return flag.Lookup("test.v") != nil + }) +} + var controlDebugFlags = getControlDebugFlags() func getControlDebugFlags() []string { @@ -496,7 +506,7 @@ func (b *LocalBackend) maybePauseControlClientLocked() { return } networkUp := b.prevIfState.AnyInterfaceUp() - b.cc.SetPaused((b.state == ipn.Stopped && b.netMap != nil) || !networkUp) + b.cc.SetPaused((b.state == ipn.Stopped && b.netMap != nil) || (!networkUp && !inTest())) } // linkChange is our network monitor callback, called whenever the network changes.