Skip to content

Commit b1998e4

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
test(webapp): make continue outage test deterministic
Makes the database outage resume test deterministic by coordinating recovery with an observed retry and using test specific retry timing. Mono-RevId: 31fbed2904653dacfe7e8a458097113fa1fbae6b
1 parent 87389fd commit b1998e4

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

‎apps/webapp/app/routes/engine.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.continue.e2e.test.ts‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { startTestServer, type TestServer } from "@internal/testcontainers/webapp";
22
import { ApiClient } from "@trigger.dev/core/v3";
33
import { SupervisorHttpClient, WORKER_HEADERS } from "@trigger.dev/core/v3/runEngineWorker";
4-
import { setTimeout } from "node:timers/promises";
54
import { Client } from "pg";
65
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
76
import {
@@ -13,11 +12,18 @@ import {
1312

1413
const INSTANCE_NAME = "continue-e2e";
1514
const RUNNER_ID = "runner-continue-e2e";
15+
const E2E_RETRY_BUDGET = {
16+
budgetMs: 30_000,
17+
minDelayMs: 100,
18+
maxDelayMs: 500,
19+
minAttemptBudgetMs: 1_000,
20+
};
1621

1722
let server: TestServer;
1823
let fixtures: EngineFixtures;
1924
let api: ApiClient;
2025
let supervisor: SupervisorHttpClient;
26+
let retryableContinueFailures = 0;
2127

2228
beforeAll(async () => {
2329
server = await startTestServer({
@@ -32,6 +38,11 @@ beforeAll(async () => {
3238
workerToken: fixtures.workerGroupToken,
3339
instanceName: INSTANCE_NAME,
3440
managedWorkerSecret: MANAGED_WORKER_SECRET,
41+
onHttpRequestComplete(metric) {
42+
if (metric.name === "continue_run_execution" && metric.status === "503") {
43+
retryableContinueFailures++;
44+
}
45+
},
3546
});
3647
}, 180_000);
3748

@@ -69,8 +80,12 @@ describe("continue after a restore from a checkpoint", () => {
6980
);
7081
expect(duringOutage.status).toBe(503);
7182

72-
continued = continueRun(runId, snapshotId, { budgetMs: 30_000 });
73-
await setTimeout(3_000);
83+
const failuresBeforeContinue = retryableContinueFailures;
84+
continued = continueRun(runId, snapshotId, E2E_RETRY_BUDGET);
85+
await vi.waitFor(
86+
() => expect(retryableContinueFailures).toBeGreaterThan(failuresBeforeContinue),
87+
{ timeout: 5_000, interval: 50 }
88+
);
7489
} finally {
7590
await outage.end();
7691
}
@@ -82,7 +97,16 @@ describe("continue after a restore from a checkpoint", () => {
8297
}, 60_000);
8398
});
8499

85-
function continueRun(runId: string, snapshotId: string, retryBudget?: { budgetMs: number }) {
100+
function continueRun(
101+
runId: string,
102+
snapshotId: string,
103+
retryBudget?: {
104+
budgetMs: number;
105+
minDelayMs?: number;
106+
maxDelayMs?: number;
107+
minAttemptBudgetMs?: number;
108+
}
109+
) {
86110
return supervisor.continueRunExecution(runId, snapshotId, RUNNER_ID, fixtures.environmentId, {
87111
retryBudget,
88112
});

0 commit comments

Comments
 (0)