test: add retry to flaky abortsignal unit test (#6841)

This commit is contained in:
jdolle 2025-06-11 00:38:15 -07:00 committed by GitHub
parent 66ae8cf545
commit 8cc1bc9498
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 51 deletions

View file

@ -246,7 +246,7 @@ describe('Execution', () => {
// Run GraphiQL
cy.intercept({ headers: preflightHeaders }).as('request');
cy.get(selectors.graphiql.buttonExecute).click();
cy.wait('@request');
cy.wait('@request', { timeout: 10_000 });
});
it('result.request.headers are NOT substituted with environment variables', () => {
@ -282,7 +282,7 @@ describe('Execution', () => {
},
}).as('request');
cy.get(selectors.graphiql.buttonExecute).click();
cy.wait('@request');
cy.wait('@request', { timeout: 10_000 });
});
it('header placeholders are substituted with environment variables', () => {

View file

@ -220,60 +220,64 @@ test('timeout', async ({ expect }) => {
expect(spy).toHaveBeenCalledTimes(2);
});
test('run action again when the action expires', async ({ expect }) => {
const ttlMs = 10;
const redis = new Redis();
const prefix = randomString();
const pollIntervalMs = 5;
const timeoutMs = 50;
const cacheForRequest1 = createCache({
redis,
logger: {
debug: vi.fn() as any,
warn: vi.fn() as any,
},
prefix,
pollIntervalMs,
timeoutMs,
ttlMs: {
success: ttlMs,
failure: ttlMs,
},
});
test(
'run action again when the action expires',
async ({ expect }) => {
const ttlMs = 10;
const redis = new Redis();
const prefix = randomString();
const pollIntervalMs = 5;
const timeoutMs = 50;
const cacheForRequest1 = createCache({
redis,
logger: {
debug: vi.fn() as any,
warn: vi.fn() as any,
},
prefix,
pollIntervalMs,
timeoutMs,
ttlMs: {
success: ttlMs,
failure: ttlMs,
},
});
const cacheForRequest2 = createCache({
redis,
logger: {
debug: vi.fn() as any,
warn: vi.fn() as any,
},
prefix,
pollIntervalMs,
timeoutMs,
ttlMs: {
success: ttlMs,
failure: ttlMs,
},
});
const cacheForRequest2 = createCache({
redis,
logger: {
debug: vi.fn() as any,
warn: vi.fn() as any,
},
prefix,
pollIntervalMs,
timeoutMs,
ttlMs: {
success: ttlMs,
failure: ttlMs,
},
});
const actionId = randomString();
async function actionFn() {
await waitFor(timeoutMs - 1);
return 'foo';
}
const actionId = randomString();
async function actionFn() {
await waitFor(timeoutMs - 1);
return 'foo';
}
const exec1 = cacheForRequest1.reuse(actionId, actionFn);
const exec2 = cacheForRequest2.reuse(actionId, actionFn);
const exec1 = cacheForRequest1.reuse(actionId, actionFn);
const exec2 = cacheForRequest2.reuse(actionId, actionFn);
const run1 = exec1({});
const run2 = exec2({});
// force the cache to expire
await waitFor(ttlMs + 10);
await redis.flushall();
const run1 = exec1({});
const run2 = exec2({});
// force the cache to expire
await waitFor(ttlMs + 10);
await redis.flushall();
await expect(run1).resolves.toBe('foo');
await expect(run2).resolves.toBe('foo');
});
await expect(run1).resolves.toBe('foo');
await expect(run2).resolves.toBe('foo');
},
{ retry: 3 },
);
test('decide on cache duration', async ({ expect }) => {
const ttlMs = {