You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/tstest
Alex Chan 7953592f40 tstest/integration: get TestOneNodeUpAuth to pass when offline
How TestOneNodeUpAuth works:

* it starts a test version of tailscaled
* it runs `tailscale up`
* it checks that tailscaled becomes "Running"

However, if the network is down, the test either fails or times out,
because tailscaled never becomes Running.

## Why does the test fail?

ipn only becomes Running when it sees at least one live peer or DERP
connection:
0cc1b2ff76/ipn/ipnlocal/local.go (L5861-L5866)

The test only uses a single node, so it's never going to see a peer --
it has to wait to see a DERP server.  The test environment does have
a DERP map of in-memory DERP nodes, but we aren't connecting to them.

magicsock sets the preferred DERP server in `updateNetInfo()`, but this
function returns early if the network is down.
0cc1b2ff76/wgengine/magicsock/magicsock.go (L1053-L1106)

Because we're checking the real network, this prevents ipn from entering
"Running" and causes the test to fail.

## What's the fix?

In tests, we can assume the network is up unless we're explicitly testing
the behaviour of tailscaled when the network is down.

We do something similar in magicsock/derp.go, where we assume we're
connected to control unless explicitly testing otherwise:
7d2101f352/wgengine/magicsock/derp.go (L166-L177)

This is the template for the changes to `networkDown()`.

Additionally, the `testenv.InTest()` function currently checks for the
`-test.v` flag, but this isn't visible to the version of tailscaled
running in the test environment.  Instead, we add a new `TEST` env var
so this process knows it's inside a test.

Fixes #17122

Signed-off-by: Alex Chan <alexc@tailscale.com>
3 months ago
..
archtest all: cleanup unused code, part 1 (#10661) 2 years ago
deptest ipn/ipnlocal: use policyclient.Client always, stop using global syspolicy funcs 3 months ago
integration tstest/integration: get TestOneNodeUpAuth to pass when offline 3 months ago
iosdeps feature/capture: move packet capture to feature/*, out of iOS + CLI 10 months ago
jsdeps all: use math/rand/v2 more 2 years ago
mts tstest/mts: add multiple-tailscaled development tool 9 months ago
natlab tstest/natlab: fix conn.Close race with conn.ReadFromUDPAddrPort (#16710) 4 months ago
nettest net/{netx,memnet},all: add netx.DialFunc, move memnet Network impl 8 months ago
tailmac tstest/tailmac: add support for mounting host directories in the guest (#13957) 1 year ago
tlstest tstest/tlstest: simplify, don't even bake in any keys 6 months ago
tools go.{mod,sum},tstest/tools,k8s-operator,cmd/k8s-operator: autogenerate CRD API docs (#12884) 1 year ago
allocs.go all: update copyright and license headers 3 years ago
clock.go tstime: add Since method (#8622) 2 years ago
clock_test.go all: use Go 1.22 range-over-int 2 years ago
log.go net/portmapper: fix test flakes from logging after test done 7 months ago
log_test.go all: update copyright and license headers 3 years ago
reflect.go net/dns: fix IsZero and Equal methods on OSConfig 1 year ago
resource.go tstest: parse goroutines for diff in ResourceCheck (#15619) 8 months ago
resource_test.go tstest: parse goroutines for diff in ResourceCheck (#15619) 8 months ago
test-wishlist.md wf/firewall: allow link-local multicast for permitted local routes when the killswitch is on on Windows 1 year ago
tstest.go ipn/{conffile,ipnlocal}: start booting tailscaled from a config file w/ auth key 2 years ago
tstest_test.go tstest: add method to Replace values for tests 3 years ago