albpool

package
v2.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func HealthyTarget added in v2.0.2

func HealthyTarget(h http.Handler) (*pool.Target, *healthcheck.Status)

HealthyTarget builds a single *pool.Target with its status pre-set to StatusPassing.

func NamedHandler added in v2.0.2

func NamedHandler(name string) http.Handler

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

func New(healthyFloor int, hs []http.Handler) (pool.Pool,
	[]*pool.Target, []*healthcheck.Status,
)

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

func NewHealthy(handlers []http.Handler) (pool.Pool,
	[]*pool.Target, []*healthcheck.Status,
)

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

func NewParentGET(t testing.TB) *http.Request

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

func NewParentPOST(t testing.TB, body io.Reader) *http.Request

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

func PanicHandler() http.Handler

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

func RequireFanoutAttemptDelta(t testing.TB, mech, variant string, want float64, fn func())

RequireFanoutAttemptDelta runs fn and asserts that the metrics.ALBFanoutAttempts counter for (mech, variant) advanced by want.

func RequireFanoutFailureDelta added in v2.0.2

func RequireFanoutFailureDelta(t testing.TB, mech, variant, reason string, want float64, fn func())

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

func ServeAndWait(t testing.TB, h http.Handler, w http.ResponseWriter, r *http.Request)

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

func SizedBodyHandler(code, size int) http.Handler

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

func StatusHandler(code int, body string) http.Handler

StatusHandler returns an http.Handler that writes the given status code and body. Replaces the inline statusHandler closures in fr/, nlm/, fanout/.

func Target added in v2.0.2

func Target(h http.Handler) (*pool.Target, *healthcheck.Status)

Target builds a single *pool.Target backed by a fresh status. Replaces the mkTarget / mkFlapTarget helpers re-implemented across fanout tests.

func WaitHealthy added in v2.0.2

func WaitHealthy(t testing.TB, p pool.Pool, want int)

WaitHealthy polls p.Targets() until its length equals want or the 2s deadline elapses. On timeout it calls t.Fatalf. Replaces the time.Sleep(250 * time.Millisecond) idiom used to wait for health propagation.

Types

type HealthFlipResult added in v2.0.2

type HealthFlipResult struct {
	FlipperIters   int64
	FanoutIters    int64
	SucceededSlots int64
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL