summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFernando Serboncini <fserb@tailscale.com>2026-02-25 17:41:51 -0500
committerGitHub <noreply@github.com>2026-02-25 17:41:51 -0500
commit54de5daae00cd491d7c7174d400be6f0c630a5f0 (patch)
tree95715bf8d0820469191fbe9961bb33d16fbfff00
parent518d2417003657f955b98a546987e376ad9fe740 (diff)
downloadtailscale-54de5daae00cd491d7c7174d400be6f0c630a5f0.tar.xz
tailscale-54de5daae00cd491d7c7174d400be6f0c630a5f0.zip
tstest/integration/nat: use per-call timeout in natlab ping (#18811)
The test ping() passed the full 60s context to each PingWithOpts call, so if the first attempt hung (DERP not yet registered), the retry loop never reached attempt 2. Use a 2s per-call timeout instead. Updates: #18810 Signed-off-by: Fernando Serboncini <fserb@tailscale.com>
-rw-r--r--tstest/integration/nat/nat_test.go33
1 files changed, 18 insertions, 15 deletions
diff --git a/tstest/integration/nat/nat_test.go b/tstest/integration/nat/nat_test.go
index 56d602222..2322e243a 100644
--- a/tstest/integration/nat/nat_test.go
+++ b/tstest/integration/nat/nat_test.go
@@ -415,7 +415,7 @@ func (nt *natTest) runTest(addNode ...addNodeFunc) pingRoute {
return ""
}
- pingRes, err := ping(ctx, clients[0], sts[1].Self.TailscaleIPs[0])
+ pingRes, err := ping(ctx, t, clients[0], sts[1].Self.TailscaleIPs[0])
if err != nil {
t.Fatalf("ping failure: %v", err)
}
@@ -450,35 +450,38 @@ const (
routeNil pingRoute = "nil" // *ipnstate.PingResult is nil
)
-func ping(ctx context.Context, c *vnet.NodeAgentClient, target netip.Addr) (*ipnstate.PingResult, error) {
- n := 0
- var res *ipnstate.PingResult
- anyPong := false
- for n < 10 {
- n++
- pr, err := c.PingWithOpts(ctx, target, tailcfg.PingDisco, tailscale.PingOpts{})
+func ping(ctx context.Context, t testing.TB, c *vnet.NodeAgentClient, target netip.Addr) (*ipnstate.PingResult, error) {
+ var lastRes *ipnstate.PingResult
+ for n := range 10 {
+ t.Logf("ping attempt %d to %v ...", n+1, target)
+ pingCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
+ pr, err := c.PingWithOpts(pingCtx, target, tailcfg.PingDisco, tailscale.PingOpts{})
+ cancel()
if err != nil {
- if anyPong {
- return res, nil
+ t.Logf("ping attempt %d error: %v", n+1, err)
+ if ctx.Err() != nil {
+ break
}
- return nil, err
+ continue
}
if pr.Err != "" {
return nil, errors.New(pr.Err)
}
+ t.Logf("ping attempt %d: derp=%d endpoint=%v latency=%v", n+1, pr.DERPRegionID, pr.Endpoint, pr.LatencySeconds)
if pr.DERPRegionID == 0 {
return pr, nil
}
- res = pr
+ lastRes = pr
select {
case <-ctx.Done():
+ return lastRes, nil
case <-time.After(time.Second):
}
}
- if res == nil {
- return nil, errors.New("no ping response")
+ if lastRes != nil {
+ return lastRes, nil
}
- return res, nil
+ return nil, fmt.Errorf("no ping response (ctx: %v)", ctx.Err())
}
func up(ctx context.Context, c *vnet.NodeAgentClient) error {