mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
* perf(db): add jitter to stagger due-on-restart connections - Add MIN_RESTART_REFRESH_JITTER_MS=500 and MAX_RESTART_REFRESH_JITTER_MS=5000 - Replace fixed stagger delay with stagger + random jitter in sweep() - Export sweep() for testing (marked @internal) - Test: 3 connections with 100ms base stagger, verify all processed - Uses Promise.withResolvers() pattern * fix(test): make the sweep jitter test actually assert the jitter floor The "sweep processes all connections with stagger + jitter delay" test asserted elapsed >= 50ms, which was already trivially satisfied by the pre-existing fixed stagger alone (3 connections -> 2 gaps * 100ms = 200ms), so the test passed identically whether or not the jitter change was present and never actually exercised the new behavior. Tighten the bound to >= 1000ms: with MIN_RESTART_REFRESH_JITTER_MS=500 and MAX=5000, the true floor with jitter is 2 * (100 + 500) = 1200ms — a hard guarantee (setTimeout never fires early), not a probabilistic one. Verified this fails (205ms) with the jitter term zeroed out and passes (7-9s, within the [1200ms, 10200ms] range) with it restored. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(health): make jitter configurable via env vars and tighten test assertion - Replace hardcoded jitter [500, 5000)ms with HEALTHCHECK_JITTER_MIN_MS / HEALTHCHECK_JITTER_MAX_MS env vars (defaults 500/5000). - In test: set HEALTHCHECK_STAGGER_MS=1, HEALTHCHECK_JITTER_MIN_MS=100, HEALTHCHECK_JITTER_MAX_MS=100 (fixed jitter), assert elapsed >= 190ms. - Without jitter: 2 gaps * 1ms = ~2ms. With jitter: 2 gaps * 101ms = ~202ms. The assert proves jitter is applied. Fixes #6919 * refactor(health): compact jitter await + tighten comments (file-size cap) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: oyi77 <oyi77@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>