gw-04 — Verification

One command

cd gw-04-connection-management && bash scripts/verify.sh

What the tests prove

TestInvariant
TestPoolReusea put-then-get reuses the warm connection (Created==1, Reused==1)
TestNoPoolIsAllChurnmaxIdle=0 → every request dials (Created==100) — pure churn baseline
TestPoolingReducesChurnmaxIdle=8 → 100 cycles dial once, reuse 99 times
TestIdleEvictionCausesChurna too-short idle TTL evicts and re-dials — over-tuning re-creates churn
TestPerLoopIndependenceper-loop pools each dial their own conn (the trade-off), then reuse within a loop
TestVanDerCorputKnownValuessequence is exactly 0, .5, .25, .75, .125, .625, .375, .875
TestSubsetConnectionMathsubsetting cuts N×M to N×subset (≥10× here)
TestSubsetBalanceevery origin is covered (no cold origins); max coverage within a sane band of ideal
TestSubsetStabilityVsHashModthe ring is strictly more stable than hash-mod and does not reshuffle everything when one origin leaves

All under -race.

Demo assertions (churnsim, in verify.sh)

The demo prints, for 1000 origins / 500 gateways / subset 20:

  • 500000 → 10000 connections (50× fewer),
  • coverage min/p50/max ≈ 5/10/15 against ideal 10,
  • on one origin leaving: ring ~11/500 vs hash-mod ~259/500 gateways changed.

What "green" does NOT guarantee

  • No real sockets. The pool is abstracted over a Resource so churn is measured deterministically; wiring it to net.Conn/http.Transport is an exercise (GUIDE §6.1).
  • No live LB within the subset. P2C/outlier ejection over the subset is gw-06.
  • No debounced re-subsetting. Membership-churn debouncing is an exercise (GUIDE §6.3); production needs it so the fix doesn't cause churn.