Tests: fix two CI flakes seen on main #68
No files matched your search
@@ -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 */ }
|
||||
|
||||
+5
-2
@@ -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', () => {
|
||||
|
||||
Reference in new issue
Block a user