From 6d289a3bce38869d1c4434841db3f3f1510799ec Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 23 Nov 2026 00:57:53 -0500 Subject: [PATCH] Tests: fix two CI flakes seen on main - calculateNextRun interval: bounded by the clock before and after the call (its first use loads cron-parser, which took 30 s once on a loaded runner and broke the fixed 1 s tolerance). - Integration helper: retry a GET once when a pooled keep-alive connection is reset (ECONNRESET as the server closes it); writes are never retried. Co-Authored-By: Claude Opus 5.5 --- tests/integration/helpers.js | 13 ++++++++++++- tests/utils.test.js | 7 +++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/integration/helpers.js b/tests/integration/helpers.js index 064f4e6..be3b18d 100644 --- a/tests/integration/helpers.js +++ b/tests/integration/helpers.js @@ -18,11 +18,22 @@ const SSO = { }; async function api(method, url, { headers = {}, body } = {}) { - const res = await fetch(BASE + url, { + const send = () => fetch(BASE + url, { method, headers: { ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}), ...headers }, body: body !== undefined ? JSON.stringify(body) : undefined, }); + let res; + try { + res = await send(); + } catch (e) { + // A pooled keep-alive connection can be closed by the server (5 s idle timeout) just + // as the client reuses it: ECONNRESET. Retry once, but only reads; a write might + // already have taken effect. + const reset = e && e.cause && e.cause.code === 'ECONNRESET'; + if (method !== 'GET' || !reset) throw e; + res = await send(); + } const text = await res.text(); let json = null; try { json = JSON.parse(text); } catch { /* not JSON */ } diff --git a/tests/utils.test.js b/tests/utils.test.js index 49dc18a..9a0d40b 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -123,10 +123,13 @@ describe('evalCondition', () => { describe('calculateNextRun', () => { test('interval: returns a date ~N minutes in the future', () => { + // Bounded by the clock before and after the call: its first use loads cron-parser, + // which took 30 s once on a loaded CI runner and broke a fixed 1 s tolerance. const before = Date.now(); const result = calculateNextRun('interval', '30'); - expect(result.getTime()).toBeGreaterThanOrEqual(before + 30 * 60000 - 100); - expect(result.getTime()).toBeLessThanOrEqual(before + 30 * 60000 + 1000); + const after = Date.now(); + expect(result.getTime()).toBeGreaterThanOrEqual(before + 30 * 60000); + expect(result.getTime()).toBeLessThanOrEqual(after + 30 * 60000); }); test('interval: throws on non-positive value', () => {