1
0
mirror of https://github.com/redis/go-redis.git synced 2026-10-24 07:59:20 +03:00
Files
go-redis/probe_test.go
Nedyalko Dyakov c5cad058c7 test(tests): TCP-probe before Ping in skip gates (#4001)
Tests that skip when Redis is absent gated on a client Ping to a
hardcoded/helper address. A Ping to an addr with nothing listening does
not fail fast: it pays the dial-retry (DialerRetries, default 5) plus
command-retry budget first, ~1.7s per call. A recent RE integration
nightly spent ~1.6 min across 68 such skips.

Probe the address with a short-timeout TCP dial first, which fails in
microseconds on connection-refused, then keep the existing Ping so a
reachable-but-unusable server still skips rather than proceeds.
2026-08-31 14:18:10 +03:00

28 lines
1.0 KiB
Go

package redis_test
import (
"net"
"time"
)
// probeRedis reports whether a TCP listener answers at addr within a short
// timeout. Tests that skip when Redis is absent call this before building a
// client and Ping-ing it: a Ping to an addr with nothing listening does not
// return immediately, it pays go-redis's dial-retry (DialerRetries, 5 by
// default) plus command-retry (MaxRetries) budget first — ~1.7s per call. In an
// environment without a local Redis (for example the RE nightly, whose real
// endpoint is remote), hundreds of such skips add up to minutes of wasted wall
// time. A single short-timeout TCP dial fails in microseconds on
// connection-refused instead.
//
// A nil return only means something is listening; callers keep their Ping so a
// reachable-but-unusable server (auth required, a different service on the port)
// still skips rather than proceeds.
func probeRedis(addr string) error {
c, err := net.DialTimeout("tcp", addr, 300*time.Millisecond)
if err != nil {
return err
}
return c.Close()
}