tsnet: wait for peer in netmap before pinging in setupTwoClientTest

If we dispatch a ping too early (after a later patch removes a 250ms
blockage) then the ping may be lost due to the peers not yet knowing
about each other. The ping is retained in order to setup and ensure a
wireguard session prior to test flow.

Updates #19822

Change-Id: I6cfea28931646a9387b6ffc2654e72cd846f4e55
Signed-off-by: James Tucker <james@tailscale.com>
Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
James Tucker
2026-05-28 11:27:54 -07:00
committed by James Tucker
co-authored by Brad Fitzpatrick
parent c086992f4f
commit 524a374f01
+34
View File
@@ -2285,6 +2285,37 @@ type listenTest struct {
tun *chanTUN // nil for netstack mode
}
// waitForPeerReachable blocks until s's current netmap contains the given peer
// with a non-zero HomeDERP and endpoints.
//
// This is polled via the LocalBackend's netmap rather than via the IPN bus
// because the bus does not carry HomeDERP or Endpoint deltas; the netmap
// itself is the source of truth for those fields.
func waitForPeerReachable(t *testing.T, s *Server, peer key.NodePublic) {
t.Helper()
if err := tstest.WaitFor(30*time.Second, func() error {
nm := s.lb.NetMapWithPeers()
if nm == nil {
return errors.New("no netmap yet")
}
for _, p := range nm.Peers {
if p.Key() != peer {
continue
}
if p.HomeDERP() == 0 {
return fmt.Errorf("peer %v: no HomeDERP", peer.ShortString())
}
if p.Endpoints().Len() == 0 {
return fmt.Errorf("peer %v: no endpoints", peer.ShortString())
}
return nil
}
return fmt.Errorf("peer %v not in netmap", peer.ShortString())
}); err != nil {
t.Fatalf("waitForPeerReachable(%v): %v", peer.ShortString(), err)
}
}
// 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 {
@@ -2328,6 +2359,9 @@ func setupTwoClientTest(t *testing.T, useTUN bool) *listenTest {
s2ip6 = s2status.TailscaleIPs[1]
}
waitForPeerReachable(t, s1, s2.lb.NodeKey())
waitForPeerReachable(t, s2, s1.lb.NodeKey())
lc1 := must.Get(s1.LocalClient())
must.Get(lc1.Ping(ctx, s2ip4, tailcfg.PingTSMP))