Skip to content

Commit 9ff3113

Browse files
committed
test(run-engine): update snapshot-count expectations for the collapsed trigger write
The store-routing counters now also count createRun, since the trigger path's QUEUED snapshot is written nested in the run create. The replica-lag test starts the run attempt so it still has a middle snapshot to exercise rather than degenerating to an empty comparison.
1 parent c3b390b commit 9ff3113

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

.server-changes/collapse-trigger-queued-snapshot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ area: webapp
33
type: improvement
44
---
55

6-
Triggering a task now does one less database write, so runs reach the queue marginally faster.
6+
Triggering a task now reaches the queue marginally faster.

internal-packages/run-engine/src/engine/systems/enqueueSystem.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ function createEngineOptions(redisOptions: any, prisma: any, store?: PostgresRun
4444
}
4545

4646
/**
47-
* A real PostgresRunStore subclass that counts the snapshot create method that enqueueRun's
48-
* snapshot write routes through (via executionSnapshotSystem.createExecutionSnapshot). super.*
49-
* runs the genuine store implementation, so the routing is observed over real containers without
50-
* ever mocking prisma or the store.
47+
* A real PostgresRunStore subclass that counts the store methods a run's QUEUED snapshot can be
48+
* written through: nested in `createRun` on the trigger path, or standalone via
49+
* `createExecutionSnapshot` on every re-enqueue. super.* runs the genuine store implementation, so
50+
* the routing is observed over real containers without ever mocking prisma or the store.
5151
*/
5252
class CountingPostgresRunStore extends PostgresRunStore {
5353
public snapshotCreates = 0;
@@ -59,12 +59,19 @@ class CountingPostgresRunStore extends PostgresRunStore {
5959
this.snapshotCreates++;
6060
return super.createExecutionSnapshot(input, tx);
6161
}
62+
63+
override async createRun(
64+
params: Parameters<PostgresRunStore["createRun"]>[0],
65+
tx?: any
66+
): ReturnType<PostgresRunStore["createRun"]> {
67+
this.snapshotCreates++;
68+
return super.createRun(params, tx);
69+
}
6270
}
6371

6472
describe("RunEngine enqueueRun store routing", () => {
65-
// The QUEUED snapshot written while enqueuing a run routes through the injected store.
6673
containerTest(
67-
"enqueueRun snapshot routes through the store",
74+
"the QUEUED snapshot routes through the store",
6875
async ({ prisma, redisOptions }) => {
6976
const countingStore = new CountingPostgresRunStore({ prisma, readOnlyPrisma: prisma });
7077
const engine = new RunEngine(createEngineOptions(redisOptions, prisma, countingStore));

internal-packages/run-engine/src/engine/systems/executionSnapshotSystem.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class CountingPostgresRunStore extends PostgresRunStore {
6565
return super.createExecutionSnapshot(input, tx);
6666
}
6767

68+
override async createRun(
69+
params: Parameters<PostgresRunStore["createRun"]>[0],
70+
tx?: any
71+
): ReturnType<PostgresRunStore["createRun"]> {
72+
this.creates++;
73+
return super.createRun(params, tx);
74+
}
75+
6876
override async findLatestExecutionSnapshot(
6977
runId: string,
7078
client?: any

internal-packages/run-engine/src/engine/tests/getSnapshotsSince.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,16 @@ describe("RunEngine getSnapshotsSince", () => {
11491149
);
11501150

11511151
await setTimeout(500);
1152-
await engine.dequeueFromWorkerQueue({
1152+
const dequeued = await engine.dequeueFromWorkerQueue({
11531153
consumerId: "test_replica_stale_tail",
11541154
workerQueue: "main",
11551155
});
11561156

1157+
await engine.startRunAttempt({
1158+
runId: dequeued[0].run.id,
1159+
snapshotId: dequeued[0].snapshot.id,
1160+
});
1161+
11571162
const allSnapshots = await prisma.taskRunExecutionSnapshot.findMany({
11581163
where: { runId: run.id, isValid: true },
11591164
orderBy: { createdAt: "asc" },

0 commit comments

Comments
 (0)