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>
main
Fernando Serboncini 2 months ago committed by GitHub
parent 518d241700
commit 54de5daae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 33
      tstest/integration/nat/nat_test.go

@ -415,7 +415,7 @@ func (nt *natTest) runTest(addNode ...addNodeFunc) pingRoute {
return "" 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 { if err != nil {
t.Fatalf("ping failure: %v", err) t.Fatalf("ping failure: %v", err)
} }
@ -450,35 +450,38 @@ const (
routeNil pingRoute = "nil" // *ipnstate.PingResult is nil routeNil pingRoute = "nil" // *ipnstate.PingResult is nil
) )
func ping(ctx context.Context, c *vnet.NodeAgentClient, target netip.Addr) (*ipnstate.PingResult, error) { func ping(ctx context.Context, t testing.TB, c *vnet.NodeAgentClient, target netip.Addr) (*ipnstate.PingResult, error) {
n := 0 var lastRes *ipnstate.PingResult
var res *ipnstate.PingResult for n := range 10 {
anyPong := false t.Logf("ping attempt %d to %v ...", n+1, target)
for n < 10 { pingCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
n++ pr, err := c.PingWithOpts(pingCtx, target, tailcfg.PingDisco, tailscale.PingOpts{})
pr, err := c.PingWithOpts(ctx, target, tailcfg.PingDisco, tailscale.PingOpts{}) cancel()
if err != nil { if err != nil {
if anyPong { t.Logf("ping attempt %d error: %v", n+1, err)
return res, nil if ctx.Err() != nil {
break
} }
return nil, err continue
} }
if pr.Err != "" { if pr.Err != "" {
return nil, errors.New(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 { if pr.DERPRegionID == 0 {
return pr, nil return pr, nil
} }
res = pr lastRes = pr
select { select {
case <-ctx.Done(): case <-ctx.Done():
return lastRes, nil
case <-time.After(time.Second): case <-time.After(time.Second):
} }
} }
if res == nil { if lastRes != nil {
return nil, errors.New("no ping response") 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 { func up(ctx context.Context, c *vnet.NodeAgentClient) error {

Loading…
Cancel
Save