Documentation
¶
Overview ¶
Package albpool provides shared test helpers for constructing ALB pools, targets, and parent requests. Helpers do not register cleanup; callers own pool lifetime via defer p.Stop(). Helpers never call t.Fatal from inside a handler or spawned goroutine; that pattern interacts badly with goleak.
Index ¶
- func HealthyTarget(h http.Handler) (*pool.Target, *healthcheck.Status)
- func NamedHandler(name string) http.Handler
- func New(healthyFloor int, hs []http.Handler) (pool.Pool, []*pool.Target, []*healthcheck.Status)
- func NewHealthy(handlers []http.Handler) (pool.Pool, []*pool.Target, []*healthcheck.Status)
- func NewParentGET(t testing.TB) *http.Request
- func NewParentPOST(t testing.TB, body io.Reader) *http.Request
- func PanicHandler() http.Handler
- func RequireCounterDelta(t testing.TB, vec *prometheus.CounterVec, labels []string, want float64, ...)
- func RequireFanoutAttemptDelta(t testing.TB, mech, variant string, want float64, fn func())
- func RequireFanoutFailureDelta(t testing.TB, mech, variant, reason string, want float64, fn func())
- func RunPostBodyFanoutRace(t testing.TB, mkHandler func(p pool.Pool) http.Handler, body string, ...)
- func ServeAndWait(t testing.TB, h http.Handler, w http.ResponseWriter, r *http.Request)
- func SizedBodyHandler(code, size int) http.Handler
- func StatusHandler(code int, body string) http.Handler
- func Target(h http.Handler) (*pool.Target, *healthcheck.Status)
- func WaitHealthy(t testing.TB, p pool.Pool, want int)
- type HealthFlipResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HealthyTarget ¶ added in v2.0.2
HealthyTarget builds a single *pool.Target with its status pre-set to StatusPassing.
func NamedHandler ¶ added in v2.0.2
NamedHandler returns an http.Handler that writes name as the response body with a 200 status. Useful when tests need to assert which target served a request.
func New ¶
New constructs a pool with the given healthyFloor and one target per handler. Each target's status starts at the zero value (StatusUnchecked = 0); callers that want targets dispatch-ready should use NewHealthy or invoke Set on the returned statuses.
func NewHealthy ¶ added in v2.0.2
NewHealthy builds a pool with healthyFloor=-1 and pre-sets every target's status to StatusPassing. It replaces the
p, _, st := albpool.New(-1, hs)
for _, s := range st { s.Set(0) }
time.Sleep(250 * time.Millisecond)
boilerplate. Callers should still WaitHealthy if dispatch needs the live list to converge, or invoke p.SetHealthy to bypass refresh entirely.
func NewParentGET ¶ added in v2.0.2
NewParentGET returns a GET request against the stock parent URL used by ALB tests. Fatal if request construction fails.
func NewParentPOST ¶ added in v2.0.2
NewParentPOST returns a POST request against the stock parent URL with the given body. Fatal if request construction fails.
func PanicHandler ¶ added in v2.0.2
PanicHandler returns an http.Handler that panics with a canonical simulated-upstream string.
func RequireCounterDelta ¶ added in v2.0.2
func RequireCounterDelta(t testing.TB, vec *prometheus.CounterVec, labels []string, want float64, fn func())
RequireCounterDelta runs fn and asserts the named CounterVec advanced by want for the given labels. Generalises the *FanoutDelta helpers for callers that want to assert on any Prometheus counter.
func RequireFanoutAttemptDelta ¶ added in v2.0.2
RequireFanoutAttemptDelta runs fn and asserts that the metrics.ALBFanoutAttempts counter for (mech, variant) advanced by want.
func RequireFanoutFailureDelta ¶ added in v2.0.2
RequireFanoutFailureDelta runs fn and asserts that the metrics.ALBFanoutFailures counter for (mech, variant, reason) advanced by want.
func RunPostBodyFanoutRace ¶ added in v2.0.2
func RunPostBodyFanoutRace( t testing.TB, mkHandler func(p pool.Pool) http.Handler, body string, slots, callers int, decorateResp func(w http.ResponseWriter), )
RunPostBodyFanoutRace builds a `slots`-upstream pool whose stubs verify the parent body arrives intact, then drives `callers` parallel POSTs against the handler returned by mkHandler(p). decorateResp is invoked in each upstream stub before WriteHeader (eg to set Last-Modified). Run under -race.
func ServeAndWait ¶ added in v2.0.2
ServeAndWait runs h.ServeHTTP(w, r) in a goroutine, asserts it returns within 5s, and re-raises any unrecovered panic via t.Fatalf so callers cannot keep asserting after a dead handler.
func SizedBodyHandler ¶ added in v2.0.2
SizedBodyHandler returns an http.Handler that emits a body of size bytes (filled with 'a') under an explicit Content-Length: size header with the given status code.
func StatusHandler ¶ added in v2.0.2
StatusHandler returns an http.Handler that writes the given status code and body. Replaces the inline statusHandler closures in fr/, nlm/, fanout/.
Types ¶
type HealthFlipResult ¶ added in v2.0.2
HealthFlipResult reports the iteration counts and the cumulative count of successful fanout slots observed during RunHealthFlipRace.
func RunHealthFlipRace ¶ added in v2.0.2
func RunHealthFlipRace( t testing.TB, targets pool.Targets, fanoutFn func() (slotsSucceeded int), deadline time.Duration, earlyExitFanouts int64, ) HealthFlipResult
RunHealthFlipRace toggles every target's health between Failing and Passing in one goroutine while invoking fanoutFn in another, until fanoutIters reaches earlyExitFanouts or the deadline elapses. fanoutFn must return the number of slots in the fanout that succeeded. Intended for -race coverage of the dispatch-vs-health-flap interleave; the caller is responsible for asserting invariants on the returned counts.