-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathwaitpointRace.test.ts
More file actions
111 lines (97 loc) · 3.67 KB
/
waitpointRace.test.ts
File metadata and controls
111 lines (97 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { containerTest } from "@internal/testcontainers";
import { trace } from "@internal/tracing";
import { expect } from "vitest";
import { RunEngine } from "../index.js";
import { setupAuthenticatedEnvironment, setupBackgroundWorker } from "./setup.js";
import { setTimeout } from "timers/promises";
vi.setConfig({ testTimeout: 60_000 });
describe("RunEngine Waitpoints – race condition", () => {
containerTest(
"join-row removed before run continues (failing race)",
async ({ prisma, redisOptions }) => {
const env = await setupAuthenticatedEnvironment(prisma, "PRODUCTION");
const engine = new RunEngine({
prisma,
worker: { redis: redisOptions, workers: 1, tasksPerWorker: 10, pollIntervalMs: 100 },
queue: { redis: redisOptions },
runLock: { redis: redisOptions },
machines: {
defaultMachine: "small-1x",
machines: {
"small-1x": { name: "small-1x" as const, cpu: 0.5, memory: 0.5, centsPerMs: 0.0001 },
},
baseCostInCents: 0.0001,
},
tracer: trace.getTracer("test", "0.0.0"),
});
try {
const taskIdentifier = "test-task";
await setupBackgroundWorker(engine, env, taskIdentifier);
const run = await engine.trigger(
{
number: 1,
friendlyId: "run_race",
environment: env,
taskIdentifier,
payload: "{}",
payloadType: "application/json",
context: {},
traceContext: {},
traceId: "race-trace",
spanId: "race-span",
masterQueue: "main",
queue: "task/test-task",
isTest: false,
tags: [],
},
prisma
);
const dequeued = await engine.dequeueFromMasterQueue({
consumerId: "test",
masterQueue: run.masterQueue,
maxRunCount: 10,
});
await engine.startRunAttempt({
runId: dequeued[0].run.id,
snapshotId: dequeued[0].snapshot.id,
});
// create manual waitpoint
const { waitpoint } = await engine.createManualWaitpoint({
environmentId: env.id,
projectId: env.projectId,
});
// block the run
await engine.blockRunWithWaitpoint({
runId: run.id,
waitpoints: waitpoint.id,
projectId: env.projectId,
organizationId: env.organizationId,
});
// Now we need to block the run again right after the continueRunIfUnblocked function
// is called as a result of the above completeWaitpoint call
const { waitpoint: waitpoint2 } = await engine.createManualWaitpoint({
environmentId: env.id,
projectId: env.projectId,
});
engine.registerRacepointForRun({ runId: run.id, waitInterval: 500 });
// complete the waitpoint (this will schedule a continueRunIfUnblocked job normally)
await engine.completeWaitpoint({ id: waitpoint.id });
await engine.waitpointSystem.blockRunWithWaitpoint({
runId: run.id,
waitpoints: waitpoint2.id,
projectId: env.projectId,
organizationId: env.organizationId,
});
await setTimeout(1000);
// The join row SHOULD still exist until the run progresses naturally.
const joinRow = await prisma.taskRunWaitpoint.findFirst({
where: { taskRunId: run.id, waitpointId: waitpoint2.id },
});
// Intentionally expect it to still be there – current implementation erroneously deletes it so test fails.
expect(joinRow).not.toBeNull();
} finally {
await engine.quit();
}
}
);
});