Skip to content

Commit cdfa669

Browse files
committed
test(server): the load test's read must overlap the writes
The writer signalled its milestone only after every insert had finished, so the read ran against a writer that was already done. The measurement was of a read with no write load in it, which is the opposite of what the test claims to measure. The milestone is now signalled part way through the inserts, and the writer keeps writing while the read runs. The test asserts that the writer was still going when the read started, so the overlap is pinned rather than assumed.
1 parent e73f725 commit cdfa669

1 file changed

Lines changed: 59 additions & 35 deletions

File tree

‎apps/server/src/orchestration-v2/ProjectionStoreLockWait.test.ts‎

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const FIXED_EPOCH = "2026-01-01T00:00:00.000Z";
2828
/** How many rows the writer inserts while the read runs. */
2929
const WRITE_ROWS = 400;
3030

31+
/**
32+
* How many rows the writer has inserted when it signals the read.
33+
*
34+
* The read has to start while the writer is still writing, so the milestone
35+
* is part way through the inserts, not after them.
36+
*/
37+
const WRITE_MILESTONE_ROWS = 50;
38+
3139
/**
3240
* The lock wait a read pays, and the connection it pays it on.
3341
*
@@ -168,33 +176,40 @@ const measureReadUnderWriteLoad = Effect.fn("measureReadUnderWriteLoad")(functio
168176
},
169177
});
170178

171-
// A writer, inserting rows the whole time the read runs. It signals when it
172-
// has written enough for the read to meet a busy writer.
179+
// A writer, inserting rows the whole time the read runs.
173180
//
174181
// The columns are the table's own. A row that does not insert is a failed
175182
// row, not write load, so the insert is not allowed to fail quietly: the
176183
// rows are counted afterwards and the count is asserted.
184+
//
185+
// The milestone is signalled PART WAY THROUGH the inserts, not after them, so
186+
// the read runs while the writer is still writing. A milestone at the end
187+
// would measure a read against a writer that had already finished.
177188
const writing = yield* Deferred.make<void>();
178189
let written = 0;
179-
const writer = yield* Effect.repeat(
180-
Effect.gen(function* () {
181-
yield* sql`INSERT INTO orchestration_v2_projection_checkpoints (
182-
checkpoint_id, thread_id, scope_id, run_id, node_id, ordinal_within_scope,
183-
status, captured_at, payload_json
184-
) VALUES (
185-
${crypto.randomUUID()}, ${threadId}, ${`lockwait-scope-${written}`}, ${"run"}, ${"node"},
186-
${written}, 'captured', ${FIXED_EPOCH}, '{}'
187-
)`;
188-
written += 1;
189-
}),
190-
{ times: WRITE_ROWS },
191-
).pipe(
192-
Effect.andThen(Deferred.succeed(writing, undefined)),
193-
Effect.forkChild({ startImmediately: true }),
194-
);
190+
const writer = yield* Effect.forEach(
191+
Array.from({ length: WRITE_ROWS }, (_, index) => index),
192+
(index) =>
193+
Effect.gen(function* () {
194+
yield* sql`INSERT INTO orchestration_v2_projection_checkpoints (
195+
checkpoint_id, thread_id, scope_id, run_id, node_id, ordinal_within_scope,
196+
status, captured_at, payload_json
197+
) VALUES (
198+
${crypto.randomUUID()}, ${threadId}, ${`lockwait-scope-${index}`}, ${"run"}, ${"node"},
199+
${index}, 'captured', ${FIXED_EPOCH}, '{}'
200+
)`;
201+
written += 1;
202+
if (index === WRITE_MILESTONE_ROWS - 1) {
203+
yield* Deferred.succeed(writing, undefined);
204+
}
205+
}),
206+
).pipe(Effect.forkChild({ startImmediately: true }));
195207

196208
// Wait for the milestone, not for a wall-clock duration.
197209
yield* Deferred.await(writing);
210+
// The writer is still going: the read has to overlap the writes, or it is
211+
// measuring a writer that has already finished.
212+
assert.isBelow(written, WRITE_ROWS);
198213
const started = yield* Clock.currentTimeMillis;
199214
yield* projectionStore
200215
.getThreadRecords(threadId, ["runs"])
@@ -232,31 +247,40 @@ const measureReadOnWriter = Effect.fn("measureReadOnWriter")(function* (threadId
232247
},
233248
});
234249

235-
// A writer inserting rows the whole time the read runs.
250+
// A writer, inserting rows the whole time the read runs.
236251
//
237252
// The columns are the table's own. A row that does not insert is a failed
238253
// row, not write load, so the insert is not allowed to fail quietly: the
239254
// rows are counted afterwards and the count is asserted.
255+
//
256+
// The milestone is signalled PART WAY THROUGH the inserts, not after them, so
257+
// the read runs while the writer is still writing. A milestone at the end
258+
// would measure a read against a writer that had already finished.
240259
const writing = yield* Deferred.make<void>();
241260
let written = 0;
242-
const writer = yield* Effect.repeat(
243-
Effect.gen(function* () {
244-
yield* sql`INSERT INTO orchestration_v2_projection_checkpoints (
245-
checkpoint_id, thread_id, scope_id, run_id, node_id, ordinal_within_scope,
246-
status, captured_at, payload_json
247-
) VALUES (
248-
${crypto.randomUUID()}, ${threadId}, ${`lockwait-scope-${written}`}, ${"run"}, ${"node"},
249-
${written}, 'captured', ${FIXED_EPOCH}, '{}'
250-
)`;
251-
written += 1;
252-
}),
253-
{ times: WRITE_ROWS },
254-
).pipe(
255-
Effect.andThen(Deferred.succeed(writing, undefined)),
256-
Effect.forkChild({ startImmediately: true }),
257-
);
261+
const writer = yield* Effect.forEach(
262+
Array.from({ length: WRITE_ROWS }, (_, index) => index),
263+
(index) =>
264+
Effect.gen(function* () {
265+
yield* sql`INSERT INTO orchestration_v2_projection_checkpoints (
266+
checkpoint_id, thread_id, scope_id, run_id, node_id, ordinal_within_scope,
267+
status, captured_at, payload_json
268+
) VALUES (
269+
${crypto.randomUUID()}, ${threadId}, ${`lockwait-scope-${index}`}, ${"run"}, ${"node"},
270+
${index}, 'captured', ${FIXED_EPOCH}, '{}'
271+
)`;
272+
written += 1;
273+
if (index === WRITE_MILESTONE_ROWS - 1) {
274+
yield* Deferred.succeed(writing, undefined);
275+
}
276+
}),
277+
).pipe(Effect.forkChild({ startImmediately: true }));
258278

279+
// Wait for the milestone, not for a wall-clock duration.
259280
yield* Deferred.await(writing);
281+
// The writer is still going: the read has to overlap the writes, or it is
282+
// measuring a writer that has already finished.
283+
assert.isBelow(written, WRITE_ROWS);
260284
const started = yield* Clock.currentTimeMillis;
261285
// A read on the writer connection: the same statement, without the reader.
262286
yield* sql

0 commit comments

Comments
 (0)