From 6da3c29bdb917c08b6c711eef64eb65828d3080a Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 16 Oct 2026 13:10:49 +0800 Subject: [PATCH] test(platform): skip real sleeps in teardown and GitHub retry tests Four teardown tests waited for the 2-second orphan-sweep pause, and the GitHub check-run, installation-token and webhook-delivery tests waited on 250 ms retry backoffs. They now skip only those delays and still check the same behavior. The six files take about 6 s instead of about 20 s. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../email-shared-recipients.test.ts | 2 ++ .../managed-durable-objects.test.ts | 2 ++ .../integration/zero-trust-uninstall.test.ts | 2 ++ .../packages/api/test/unit/check-run.test.ts | 10 ++++++++++ .../api/test/unit/installation-token.test.ts | 9 +++++++++ .../api/test/unit/webhook-deliveries.test.ts | 18 +++++++++++++++++- 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/platform/packages/api/test/integration/email-shared-recipients.test.ts b/platform/packages/api/test/integration/email-shared-recipients.test.ts index 96c9d14c4..bcfbbcbff 100644 --- a/platform/packages/api/test/integration/email-shared-recipients.test.ts +++ b/platform/packages/api/test/integration/email-shared-recipients.test.ts @@ -33,6 +33,7 @@ import { createOperatorToken, createTestDeployment, setupEnv, + skipOrphanSweepDelay, teardownEnv, type TestEnv, } from './helpers.ts'; @@ -615,6 +616,7 @@ describe('managed shared subdomain recipients', () => { }); it('keeps a reusable slug reserved through the real teardown route after an uncertain recipient create', async () => { + skipOrphanSweepDelay(); const { project, user, provider } = await setup({ failOn: { literalRuleCreate: { status: 503, message: 'unknown outcome' } }, failBeforeEffect: ['literalRuleCreate'], diff --git a/platform/packages/api/test/integration/managed-durable-objects.test.ts b/platform/packages/api/test/integration/managed-durable-objects.test.ts index 13a208011..9c7326a54 100644 --- a/platform/packages/api/test/integration/managed-durable-objects.test.ts +++ b/platform/packages/api/test/integration/managed-durable-objects.test.ts @@ -34,6 +34,7 @@ import { mockCfApi, readAllEvents, setupEnv, + skipOrphanSweepDelay, teardownEnv, type TestEnv, type MockCfApiHandle, @@ -434,6 +435,7 @@ describe('managed native Durable Objects', () => { }); it('cleans up project-owned namespaces through the project deletion workflow', async () => { + skipOrphanSweepDelay(); await deploy(); const worker = await durableObjectWorkerName(project.id, binding.className); const response = await app.fetch( diff --git a/platform/packages/api/test/integration/zero-trust-uninstall.test.ts b/platform/packages/api/test/integration/zero-trust-uninstall.test.ts index 61c2cddca..b8a244b9d 100644 --- a/platform/packages/api/test/integration/zero-trust-uninstall.test.ts +++ b/platform/packages/api/test/integration/zero-trust-uninstall.test.ts @@ -37,6 +37,7 @@ import { createTestUser, mockCfApi, setupEnv, + skipOrphanSweepDelay, teardownEnv, type TestEnv, } from './helpers.ts'; @@ -153,6 +154,7 @@ async function settleOperation(platform: ApiEnv['Bindings']): Promise { describe('platform uninstall check against the API database', () => { it('lets uninstall proceed once a project deletion that stopped partway is rerun', async () => { + skipOrphanSweepDelay(); const owner = await createTestUser(env.db, 'stopped-deletion-owner'); const project = await createTestProject(env.db, owner.id, 'stopped-deletion'); await env.ROUTING.put(project.slug, JSON.stringify({ projectId: project.id })); diff --git a/platform/packages/api/test/unit/check-run.test.ts b/platform/packages/api/test/unit/check-run.test.ts index 85782f009..fa9bf8692 100644 --- a/platform/packages/api/test/unit/check-run.test.ts +++ b/platform/packages/api/test/unit/check-run.test.ts @@ -76,6 +76,14 @@ function reasonsOf(spy: ReturnType, phase: string): Array o.reason); } +/** Keep every retry attempt but run its backoff timer at once. */ +function skipRetryDelay(): void { + const schedule = globalThis.setTimeout; + vi.spyOn(globalThis, 'setTimeout').mockImplementation((callback, delay, ...args) => + schedule(callback, delay === 250 ? 0 : delay, ...args), + ); +} + describe('createCheckRun', () => { let warnSpy: ReturnType; // Unique installation id per test — getInstallationToken caches the @@ -89,6 +97,7 @@ describe('createCheckRun', () => { beforeEach(() => { warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + skipRetryDelay(); }); afterEach(() => { @@ -268,6 +277,7 @@ describe('completeCheckRun', () => { beforeEach(() => { warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + skipRetryDelay(); }); afterEach(() => { diff --git a/platform/packages/api/test/unit/installation-token.test.ts b/platform/packages/api/test/unit/installation-token.test.ts index f8698a06b..e0eca2ab8 100644 --- a/platform/packages/api/test/unit/installation-token.test.ts +++ b/platform/packages/api/test/unit/installation-token.test.ts @@ -88,6 +88,14 @@ function assertSchema(spy: ReturnType, installationId: string): } } +/** Keep every retry attempt but run its backoff timer at once. */ +function skipRetryDelay(): void { + const schedule = globalThis.setTimeout; + vi.spyOn(globalThis, 'setTimeout').mockImplementation((callback, delay, ...args) => + schedule(callback, delay === 250 ? 0 : delay, ...args), + ); +} + describe('getBranchHeadComparisonStatus structured logging', () => { let warnSpy: ReturnType; // Unique installation id per test — getInstallationToken caches the @@ -101,6 +109,7 @@ describe('getBranchHeadComparisonStatus structured logging', () => { beforeEach(() => { warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + skipRetryDelay(); }); afterEach(() => { diff --git a/platform/packages/api/test/unit/webhook-deliveries.test.ts b/platform/packages/api/test/unit/webhook-deliveries.test.ts index ed96c82f8..e7347baef 100644 --- a/platform/packages/api/test/unit/webhook-deliveries.test.ts +++ b/platform/packages/api/test/unit/webhook-deliveries.test.ts @@ -1,5 +1,5 @@ import { exportPKCS8, generateKeyPair } from 'jose'; -import { afterEach, beforeAll, describe, expect, it, vi } from 'vite-plus/test'; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite-plus/test'; import type { ApiEnv } from '../../src/env.ts'; import { GITHUB_API_VERSION } from '../../src/github/installation-token.ts'; import { @@ -63,7 +63,19 @@ function pageResponse(items: Array>, nextUrl?: string): return new Response(JSON.stringify(items), { status: 200, headers }); } +/** Keep every retry attempt but run its backoff timer at once. */ +function skipRetryDelay(): void { + const schedule = globalThis.setTimeout; + vi.spyOn(globalThis, 'setTimeout').mockImplementation((callback, delay, ...args) => + schedule(callback, delay === 250 ? 0 : delay, ...args), + ); +} + describe('listFailedWebhookDeliveries', () => { + beforeEach(() => { + skipRetryDelay(); + }); + afterEach(() => { vi.restoreAllMocks(); vi.unstubAllGlobals(); @@ -246,6 +258,10 @@ describe('listFailedWebhookDeliveries', () => { }); describe('redeliverWebhookDelivery', () => { + beforeEach(() => { + skipRetryDelay(); + }); + afterEach(() => { vi.restoreAllMocks(); vi.unstubAllGlobals();