mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-03 13:56:36 +09:00
tsnet: wait for control to know s2's DERP home and endpoints in delta tests
TestPingPeerLearnedViaDelta failed on Linux and Windows with
Ping(disco): error Post ".../localapi/v0/ping?ip=100.64.0.2&size=0&type=disco": context deadline exceeded
and the same for type=TSMP. The disco variant can't be the wireguard-go
duplicate handshake race fixed by #22537, and it still failed on main
with that fix.
The test puts s1 in manual MapResponse mode, starts s2, then copies
control.Node(s2Key) into a PeersChanged delta for s1. startServer only
waits for s2's local home DERP connection, not for s2's lite map update
carrying its HomeDERP and endpoints to reach control. If the snapshot
was taken first, s1 learned an s2 with no DERP home and no endpoints,
and because s1's automatic map responses are suppressed it never got
the later update, so neither disco nor TSMP pings could reach s2.
TestPingSubnetRouteOfDeltaPeer had the same pattern.
Add controlNodeReachable, which polls control until the node has a
HomeDERP and endpoints, and use it for both snapshots.
Injecting a random 0-300ms sleep before controlclient's SendUpdate
makes the original test fail nearly every run with the exact CI
errors (8/8 subtests); with this change 0 failures in 6 runs each of both
tests under the same injection.
flakestress -p 4 -taskset 0-1 -duration 8m, no injection:
before: 2 failures in 1128 runs (both Ping(disco) deadline)
after: 0 failures in 1148 runs
Fixes #22562
Change-Id: Ic5f0e1498d566a89102d92c216ae892a293d5472
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
1 parent
66e3d823c7
commit
c3a92572e8
1 file changed
+28
-2
+28
-2
@@ -2009,7 +2009,7 @@ func testPingPeerLearnedViaDelta(t *testing.T, pt tailcfg.PingType) {
|
||||
|
||||
// Snapshot s2's node-as-seen-by-control and inject it into s1's
|
||||
// stream as a PeersChanged delta.
|
||||
s2Node := control.Node(s2Key)
|
||||
s2Node := controlNodeReachable(t, control, s2Key)
|
||||
if !control.AddRawMapResponse(s1Key, &tailcfg.MapResponse{
|
||||
PeersChanged: []*tailcfg.Node{s2Node},
|
||||
}) {
|
||||
@@ -2100,7 +2100,7 @@ func TestPingSubnetRouteOfDeltaPeer(t *testing.T) {
|
||||
|
||||
// Inject s2 into s1 as a PeersChanged delta with the subnet route
|
||||
// in AllowedIPs.
|
||||
s2Node := control.Node(s2Key)
|
||||
s2Node := controlNodeReachable(t, control, s2Key)
|
||||
s2Node.PrimaryRoutes = []netip.Prefix{subnetPrefix}
|
||||
s2Node.AllowedIPs = append(s2Node.AllowedIPs, subnetPrefix)
|
||||
if !control.AddRawMapResponse(s1Key, &tailcfg.MapResponse{
|
||||
@@ -2847,6 +2847,32 @@ func waitForPeerReachable(t *testing.T, s *Server, peer key.NodePublic) {
|
||||
}
|
||||
}
|
||||
|
||||
// controlNodeReachable polls control until its record of the node with the
|
||||
// given key has a non-zero HomeDERP and endpoints, and returns that record.
|
||||
//
|
||||
// Tests that hand-craft MapResponse deltas from a control snapshot need this;
|
||||
// [startServer] only waits for the node's local DERP connection, and the node
|
||||
// may not have reported its HomeDERP and endpoints to control yet.
|
||||
func controlNodeReachable(t *testing.T, control *testcontrol.Server, k key.NodePublic) *tailcfg.Node {
|
||||
t.Helper()
|
||||
var n *tailcfg.Node
|
||||
if err := tstest.WaitFor(30*time.Second, func() error {
|
||||
n = control.Node(k)
|
||||
switch {
|
||||
case n == nil:
|
||||
return fmt.Errorf("node %v not in control", k.ShortString())
|
||||
case n.HomeDERP == 0:
|
||||
return fmt.Errorf("node %v: no HomeDERP in control", k.ShortString())
|
||||
case len(n.Endpoints) == 0:
|
||||
return fmt.Errorf("node %v: no endpoints in control", k.ShortString())
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// setupTwoClientTest creates two tsnet servers for testing.
|
||||
// If useTUN is true, s2 uses a chanTUN; otherwise it uses netstack only.
|
||||
func setupTwoClientTest(t *testing.T, useTUN bool) *listenTest {
|
||||
|
||||
Reference in new issue
Block a user