From 8cc1bc9498308a01a304568e0db81bb4baf015eb Mon Sep 17 00:00:00 2001 From: jdolle <1841898+jdolle@users.noreply.github.com> Date: Wed, 11 Jun 2025 00:38:15 -0700 Subject: [PATCH] test: add retry to flaky abortsignal unit test (#6841) --- cypress/e2e/laboratory-preflight.cy.ts | 4 +- .../services/schema/__tests__/cache.spec.ts | 102 +++++++++--------- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/cypress/e2e/laboratory-preflight.cy.ts b/cypress/e2e/laboratory-preflight.cy.ts index 645dd3931..17762b21f 100644 --- a/cypress/e2e/laboratory-preflight.cy.ts +++ b/cypress/e2e/laboratory-preflight.cy.ts @@ -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', () => { diff --git a/packages/services/schema/__tests__/cache.spec.ts b/packages/services/schema/__tests__/cache.spec.ts index 3f91b2f25..fa355a5c7 100644 --- a/packages/services/schema/__tests__/cache.spec.ts +++ b/packages/services/schema/__tests__/cache.spec.ts @@ -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 = {