Public: anyone can read this; the crew can change it.

Full suite red: test/flow-clock.test.ts #11989

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/11987-full-suite-red-test-flow-clock-test-ts → main 1 commit fork 1 thread · 1 unresolved

  • Merged. mason/11987-full-suite-red-test-flow-clock-test-ts was merged into main as 30519a7.

Review

Sign in to review this change.
1 file changed +5 −6
src/flow/pipeline.ts +5 −6
@@ -150,13 +150,12 @@ export function waitingOffThread(db: Database, sql: string, ...args: string[]):
150150 * first count (nothing to serve yet), a database with no file, or a worker
151151 * that has failed for long is counted on the thread.
152152 */
153 function waitingTally(db: Database, sql: string, ...args: string[]): Tally {
153 function waitingTally(db: Database, now: number, sql: string, ...args: string[]): Tally {
154154 if (WAITING_REUSE_MS === 0) return countWaiting(db, sql, ...args);
155155 let kept = waitingKept.get(db);
156156 if (kept === undefined) waitingKept.set(db, (kept = new Map()));
157157 // A `since` cutoff argument moves every call; the stage, not the instant, is the key.
158158 const hit = kept.get(sql);
159 const now = Date.now();
160159 if (hit !== undefined && now - hit.at < WAITING_REUSE_MS) return hit.tally;
161160 const filed = db.filename !== "" && db.filename !== ":memory:";
162161 if (hit !== undefined && filed && now - hit.at < WAITING_REUSE_MS * WAITING_STALE_PERIODS) {
@@ -164,7 +163,7 @@ function waitingTally(db: Database, sql: string, ...args: string[]): Tally {
164163 hit.asking = true;
165164 waitingOffThread(db, sql, ...args).then(
166165 (tally) => {
167 kept.set(sql, { at: Date.now(), tally, asking: false });
166 kept.set(sql, { at: now, tally, asking: false });

Stamping with the read-start instant is acceptable and was disclosed, but add a test that pins it. Consider also not overwriting a kept entry whose at is newer than now.

168167 },
169168 () => {
170169 hit.asking = false;
@@ -246,7 +245,7 @@ function tally(db: Database, key: PipelineKey, now: Date): Tally {
246245 const iso = now.toISOString();
247246 switch (key) {
248247 case "ready":
249 return waitingTally(db, READY);
248 return waitingTally(db, now.getTime(), READY);
250249 case "building":
251250 return runTally(db, "agent", "reason != 'review'", iso);
252251 case "check-queue":
@@ -256,9 +255,9 @@ function tally(db: Database, key: PipelineKey, now: Date): Tally {
256255 case "review":
257256 return runTally(db, "agent", "reason = 'review'", iso);
258257 case "approved":
259 return waitingTally(db, APPROVED);
258 return waitingTally(db, now.getTime(), APPROVED);
260259 case "landed":
261 return waitingTally(db, LANDED, new Date(now.getTime() - 7 * DAY_MS).toISOString());
260 return waitingTally(db, now.getTime(), LANDED, new Date(now.getTime() - 7 * DAY_MS).toISOString());
262261 case "live":
263262 return liveTally(db, new Date(now.getTime() - DAY_MS).toISOString());
264263 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs