gw-04 — Verification
One command
cd gw-04-connection-management && bash scripts/verify.sh
What the tests prove
| Test | Invariant |
|---|---|
TestPoolReuse | a put-then-get reuses the warm connection (Created==1, Reused==1) |
TestNoPoolIsAllChurn | maxIdle=0 → every request dials (Created==100) — pure churn baseline |
TestPoolingReducesChurn | maxIdle=8 → 100 cycles dial once, reuse 99 times |
TestIdleEvictionCausesChurn | a too-short idle TTL evicts and re-dials — over-tuning re-creates churn |
TestPerLoopIndependence | per-loop pools each dial their own conn (the K× trade-off), then reuse within a loop |
TestVanDerCorputKnownValues | sequence is exactly 0, .5, .25, .75, .125, .625, .375, .875 |
TestSubsetConnectionMath | subsetting cuts N×M to N×subset (≥10× here) |
TestSubsetBalance | every origin is covered (no cold origins); max coverage within a sane band of ideal |
TestSubsetStabilityVsHashMod | the 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 → 10000connections (50× fewer),- coverage min/p50/max ≈
5/10/15against ideal10, - 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
Resourceso churn is measured deterministically; wiring it tonet.Conn/http.Transportis 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.