Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(core): make main comparisons yield to other work [V4,C7]

Corey Olson67628bac7eea
diff --git a/src/gate.js b/src/gate.js
index f0b4c36a..f730d7ab 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -227,14 +227,14 @@ function hasPipeline(command) {
return false;
}
-/** Run work under the machine gate queue, keeping landing gates ahead of ordinary gates and item checks last.
+/** Run work under the machine queue: landing gates, ordinary gates, item checks, then diagnostics.
*
* @param {string} root - Checkout used to locate the machine resource database.
* @param {(lease: { waitMs: number }) => any | Promise<any>} action - Work to perform while holding a slot.
- * @param {{ landing?: boolean, itemCheck?: boolean, onWait?: (state: object) => void }} [options] - Queue class and progress reporter.
+ * @param {{ landing?: boolean, itemCheck?: boolean, diagnostic?: boolean, onWait?: (state: object) => void }} [options] - Queue class and progress reporter.
* @returns {Promise<any>} The action's result after releasing its lease.
*/
-export async function withGateSlot(root, action, { landing = false, itemCheck = false, onWait } = {}) {
+export async function withGateSlot(root, action, { landing = false, itemCheck = false, diagnostic = false, onWait } = {}) {
const capacityProvider = () => loadMachineSettings().gateSlots;
const lease = await takeResource({
name: 'gate',
@@ -245,6 +245,7 @@ export async function withGateSlot(root, action, { landing = false, itemCheck =
repo: root,
landing,
itemCheck,
+ diagnostic,
allowIdleCapacityUpdate: true,
onWait,
});
diff --git a/src/main-red.js b/src/main-red.js
index 59238ad8..5604a31c 100644
--- a/src/main-red.js
+++ b/src/main-red.js
@@ -161,21 +161,26 @@ export async function compareMainFailures(root, profile, onWait, output = '') {
try {
let cache = readCache(file);
const missing = files.filter(path => !['red', 'green'].includes(cache.entries[main.commit]?.[path]?.result));
- const outcomes = await Promise.allSettled(missing.map(path => withGateSlot(root, async lease => {
- const measured = await withMainCheckout(root, main.commit, async checkout => {
- const command = `${policy.config.affectedTests.trimEnd()} ${shellWord('./' + path)}`;
- const run = await runProfiledShellAsync(checkout, command, { gateSlotHeld: true, waitMs: lease.waitMs });
- return { result: run.isGreen ? 'green' : 'red' };
- });
- if (measured.unavailable) throw new Error(measured.unavailable);
- // The cache lease excludes other comparisons; synchronous persistence keeps each finished result.
- cache = readCache(file);
- cache.entries[main.commit] ??= {};
- cache.entries[main.commit][path] = measured;
- writeCache(file, cache);
- }, { onWait })));
- const failed = outcomes.find(outcome => outcome.status === 'rejected');
- if (failed) return { main: main.commit, files: [], unavailable: failed.reason?.message ?? 'main comparison could not be completed' };
+ let failed = null;
+ for (const path of missing) {
+ try {
+ await withGateSlot(root, async lease => {
+ const measured = await withMainCheckout(root, main.commit, async checkout => {
+ const command = `${policy.config.affectedTests.trimEnd()} ${shellWord('./' + path)}`;
+ const run = await runProfiledShellAsync(checkout, command, { gateSlotHeld: true, waitMs: lease.waitMs });
+ return { result: run.isGreen ? 'green' : 'red' };
+ });
+ if (measured.unavailable) throw new Error(measured.unavailable);
+ // The cache lease excludes other comparisons; persist each result before yielding again.
+ cache = readCache(file);
+ cache.entries[main.commit] ??= {};
+ cache.entries[main.commit][path] = measured;
+ writeCache(file, cache);
+ }, { diagnostic: true, onWait });
+ }
+ catch (error) { failed ??= error; }
+ }
+ if (failed) return { main: main.commit, files: [], unavailable: failed.message ?? 'main comparison could not be completed' };
cache = readCache(file);
return { main: main.commit, files: files.map(path => ({ file: path, result: cache.entries[main.commit][path].result })) };
} finally { cacheLease.release(); }
diff --git a/src/resources.js b/src/resources.js
index 30bc370a..01837c9e 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -1,4 +1,4 @@
-/** Machine and repository queues persist leases; landings, gates, and item checks run by priority [Q1,Q2,Q3,V18]. */
+/** Machine and repository queues persist leases; diagnostics yield to landings, gates and item checks [Q1,Q2,Q3,V18]. */
import { mkdirSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
import { dirname, join } from 'node:path';
@@ -44,6 +44,7 @@ function open(file) {
if (!columns.includes('started')) db.exec(`ALTER TABLE ${table} ADD COLUMN started TEXT NOT NULL DEFAULT ''`);
if (!columns.includes('landing')) db.exec(`ALTER TABLE ${table} ADD COLUMN landing INTEGER NOT NULL DEFAULT 0`);
if (!columns.includes('item_check')) db.exec(`ALTER TABLE ${table} ADD COLUMN item_check INTEGER NOT NULL DEFAULT 0`);
+ if (!columns.includes('diagnostic')) db.exec(`ALTER TABLE ${table} ADD COLUMN diagnostic INTEGER NOT NULL DEFAULT 0`);
}
db.exec('COMMIT');
transaction = false;
@@ -129,12 +130,13 @@ function update(db, action) {
}
}
-/** Current holders and the landing-first line, then ordinary gates, then item checks. */
+/** Current holders and the landing-first line, then gates, item checks and diagnostics. */
function snapshot(db, name) {
- const holders = db.prepare('SELECT agent, repo, since, landing, item_check AS itemCheck FROM holder WHERE name = ? ORDER BY since, token').all(name)
- .map((holder) => ({ ...holder, landing: holder.landing === 1, itemCheck: holder.itemCheck === 1 }));
- const line = db.prepare('SELECT agent, repo, since, landing, item_check AS itemCheck FROM waiter WHERE name = ? ORDER BY landing DESC, item_check, ticket').all(name)
- .map((waiter) => ({ ...waiter, landing: waiter.landing === 1, itemCheck: waiter.itemCheck === 1 }));
+ /** Preserve older public entries while naming diagnostics as a distinct queue class. */
+ const project = ({ diagnostic, ...entry }) => ({ ...entry, landing: entry.landing === 1,
+ itemCheck: entry.itemCheck === 1 && diagnostic !== 1, ...(diagnostic === 1 ? { diagnostic: true } : {}) });
+ const holders = db.prepare('SELECT agent, repo, since, landing, item_check AS itemCheck, diagnostic FROM holder WHERE name = ? ORDER BY since, token').all(name).map(project);
+ const line = db.prepare('SELECT agent, repo, since, landing, item_check AS itemCheck, diagnostic FROM waiter WHERE name = ? ORDER BY landing DESC, diagnostic, item_check, ticket').all(name).map(project);
return { holders, line };
}
@@ -153,6 +155,7 @@ function waiterPosition(db, name, ticket) {
const currentIndex = eligible.findIndex((waiter) => waiter.ticket === ticket);
if (currentIndex < 0) return Math.max(2, eligible.length + 1);
/** Map queue entries to their declared precedence class. */
+ // Keep the older client's ranking: diagnostic takers yield their FIFO ticket to later checks.
const rank = (waiter) => waiter.landing === 1 ? 0 : waiter.itemCheck === 1 ? 2 : 1;
const currentRank = rank(current);
return eligible.filter((waiter) => rank(waiter) < currentRank || (rank(waiter) === currentRank && waiter.ticket <= ticket)).length;
@@ -162,9 +165,9 @@ function waiterPosition(db, name, ticket) {
function pause(ms) { return new Promise((resolvePromise) => setTimeout(resolvePromise, ms)); }
/**
- * Join the queue, preserving FIFO within landing, ordinary-gate, and item-check classes.
+ * Join the existing queue; diagnostics rejoin behind later item checks so older clients agree on priority.
*
- * @param {{ name: string, capacity: number, capacityProvider?: () => number, scope?: 'machine'|'repo'|'board', root?: string, agent?: string, repo?: string, landing?: boolean, itemCheck?: boolean, onWait?: (state: object) => void, allowIdleCapacityUpdate?: boolean }} options - Resource identity and queue class.
+ * @param {{ name: string, capacity: number, capacityProvider?: () => number, scope?: 'machine'|'repo'|'board', root?: string, agent?: string, repo?: string, landing?: boolean, itemCheck?: boolean, diagnostic?: boolean, onWait?: (state: object) => void, allowIdleCapacityUpdate?: boolean }} options - Resource identity and queue class.
* @returns {Promise<{ name: string, scope: string, token: string, waitMs: number, release: () => void, renew: () => void }>}
*/
export async function takeResource(options) {
@@ -173,7 +176,9 @@ export async function takeResource(options) {
if (!Number.isSafeInteger(capacity) || capacity < 1) throw new Refused('BAD_RESOURCE_CAPACITY', 'resource capacity must be a positive integer');
const landing = options.landing === true;
const itemCheck = options.itemCheck === true;
+ const diagnostic = options.diagnostic === true;
if (landing && itemCheck) throw new Refused('BAD_RESOURCE_PRIORITY', 'a gate slot cannot be both a landing and an item check');
+ if (diagnostic && (landing || itemCheck)) throw new Refused('BAD_RESOURCE_PRIORITY', 'a diagnostic slot cannot also be a landing or an item check');
const file = databaseFile(scope, root);
const db = open(file);
const token = randomUUID();
@@ -196,16 +201,24 @@ export async function takeResource(options) {
db.prepare('UPDATE resource SET capacity = ? WHERE name = ?').run(currentCapacity, name);
}
db.prepare('INSERT INTO resource(name, capacity) VALUES (?, ?) ON CONFLICT(name) DO NOTHING').run(name, currentCapacity);
- db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck));
+ // Older queue clients see diagnostics as item checks, never as ordinary gates.
+ db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic));
});
while (true) {
const acquired = update(db, () => {
- const waiter = db.prepare('SELECT ticket, landing, item_check AS itemCheck FROM waiter WHERE token = ?').get(token);
+ let waiter = db.prepare('SELECT ticket, landing, item_check AS itemCheck, diagnostic FROM waiter WHERE token = ?').get(token);
if (!waiter) {
queuedAt = new Date().toISOString();
- const rejoined = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck));
+ const rejoined = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic));
return { acquired: false, state: { ...snapshot(db, name), position: waiterPosition(db, name, Number(rejoined.lastInsertRowid)), rejoined: true } };
}
+ if (diagnostic && db.prepare('SELECT 1 FROM waiter WHERE name=? AND diagnostic=0 AND item_check=1 AND ticket>? LIMIT 1').get(name, waiter.ticket)) {
+ // An older item-check client only knows FIFO within its class. Move behind it so both
+ // old and new callers agree who goes first instead of waiting on one another forever.
+ db.prepare('DELETE FROM waiter WHERE token=?').run(token);
+ const rejoined = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), 0, 1, 1);
+ waiter = { ticket: Number(rejoined.lastInsertRowid) };
+ }
db.prepare('UPDATE waiter SET heartbeat = ? WHERE token = ?').run(Date.now(), token);
const spot = snapshot(db, name);
const position = waiterPosition(db, name, waiter.ticket);
@@ -213,7 +226,7 @@ export async function takeResource(options) {
if (position === 1 && spot.holders.length < limit) {
db.prepare('DELETE FROM waiter WHERE token = ?').run(token);
const acquiredAt = new Date().toISOString();
- db.prepare('INSERT INTO holder(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, acquiredAt, Date.now(), Number(landing), Number(itemCheck));
+ db.prepare('INSERT INTO holder(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, acquiredAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic));
return { acquired: true, state: { ...spot, position: 0 } };
}
return { acquired: false, state: { ...spot, position } };
diff --git a/test/main-red.test.js b/test/main-red.test.js
index 1e27c0de..da1f605c 100644
--- a/test/main-red.test.js
+++ b/test/main-red.test.js
@@ -1,10 +1,13 @@
/** A red submit compares only its failed files with exact main and guides an inherited rework [V1]. */
import assert from 'node:assert/strict';
-import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
+import '../src/main-red.js'; // The private driver below invokes this production entry point.
+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { delimiter, dirname, join } from 'node:path';
import { after, test } from 'node:test';
-import { runFixtureChild, runFixtureGit } from './fixture-child.js';
+import { DatabaseSync } from 'node:sqlite';
+import { pathToFileURL } from 'node:url';
+import { runFixtureChild, runFixtureGit, startFixtureChild } from './fixture-child.js';
const BIN = join(import.meta.dirname, '../bin/pullboard.js');
const roots = [];
@@ -128,6 +131,127 @@ const FAILING_TEST = [
"test('the inherited behavior remains broken [V1]', () => assert.equal(1, 2));",
].join('\n') + '\n';
+test("a red submit's comparisons yield to other agents' work [V4,C7]", async t => {
+ const box = fixture(t, { spec: RED_SPEC, source: FAILING_TEST });
+ const control = join(box.directory, 'control');
+ mkdirSync(control);
+ const log = join(box.directory, 'order.jsonl');
+ const queue = join(box.env.PULLBOARD_MACHINE_HOME, 'resources.sqlite');
+ box.env.COMPARE_CONTROL = control;
+ box.env.COMPARE_ORDER = log;
+ assert.equal(cli(box.root, box.env, 'settings', 'gateSlots', '2').code, 0);
+ put(box.root, 'test/unrelated.test.js', "import assert from 'node:assert/strict';\nassert.equal(1, 1);\n");
+ put(box.root, 'test/runner.js', [
+ "import { appendFileSync, existsSync } from 'node:fs';",
+ "import { basename, join } from 'node:path';",
+ "import { spawnSync } from 'node:child_process';",
+ "const file = process.argv[2]; const name = basename(file);",
+ "appendFileSync(process.env.COMPARE_ORDER, JSON.stringify({phase:'start',name}) + '\\n');",
+ "while (!existsSync(join(process.env.COMPARE_CONTROL, name + '.release'))) await new Promise(done => setTimeout(done, 10));",
+ "const run = spawnSync(process.execPath, ['--test', file], { encoding:'utf8', env:process.env });",
+ "process.stdout.write(run.stdout ?? ''); process.stderr.write(run.stderr ?? '');",
+ "appendFileSync(process.env.COMPARE_ORDER, JSON.stringify({phase:'finish',name}) + '\\n');",
+ "process.exitCode = run.status ?? 1;",
+ ].join('\n'));
+ const main = commit(box.root, box.env);
+ const driver = join(box.directory, 'queue-driver.mjs');
+ writeFileSync(driver, [
+ `import { takeResource } from ${JSON.stringify(pathToFileURL(join(import.meta.dirname, '../src/resources.js')).href)};`,
+ `import { compareMainFailures } from ${JSON.stringify(pathToFileURL(join(import.meta.dirname, '../src/main-red.js')).href)};`,
+ "import { appendFileSync, existsSync, writeFileSync } from 'node:fs';",
+ "import { join } from 'node:path';",
+ "const [mode, root] = process.argv.slice(2); const control = process.env.COMPARE_CONTROL;",
+ "/** Await only a parent-owned handshake, leaving no uncontrolled fixture work. */",
+ "async function released(name) { while (!existsSync(join(control, name))) await new Promise(done => setTimeout(done, 10)); }",
+ "if (mode === 'blocker') {",
+ " const first = await takeResource({name:'gate',capacity:2,root});",
+ " const second = await takeResource({name:'gate',capacity:2,root});",
+ " writeFileSync(join(control,'blocker.ready'),'ready');",
+ " try { await released('blocker.first'); first.release(); await released('blocker.second'); }",
+ " finally { first.release(); second.release(); }",
+ "} else if (mode === 'check') {",
+ " const lease = await takeResource({name:'gate',capacity:2,root,itemCheck:true,agent:'independent-check'});",
+ " try { appendFileSync(process.env.COMPARE_ORDER, JSON.stringify({phase:'start',name:'item-check'}) + '\\n'); await released('check.release'); }",
+ " finally { lease.release(); }",
+ "} else {",
+ " const profile = {tests:['test/inherited.test.js','test/unrelated.test.js'].map(file => ({file,passed:false}))};",
+ " const result = await compareMainFailures(root,profile);",
+ " writeFileSync(join(control,mode + '.result'),JSON.stringify(result));",
+ "}",
+ ].join('\n'));
+ const children = [];
+ let maximum = 0;
+ let comparison;
+ /** Read the real private resource queue without changing its leases. */
+ const entries = table => {
+ if (!existsSync(queue)) return [];
+ const db = new DatabaseSync(queue, { readOnly: true });
+ try { db.exec('PRAGMA query_only=ON; PRAGMA busy_timeout=10000'); return db.prepare(`SELECT * FROM ${table} WHERE name='gate'`).all(); }
+ finally { db.close(); }
+ };
+ /** Retain actual completion and stderr for every bounded fixture child. */
+ const launchQueue = mode => {
+ const child = startFixtureChild(process.execPath, [driver, mode, box.root], { cwd: box.root, env: box.env, stdio: ['ignore','pipe','pipe'] });
+ let error = '';
+ child.stdout.resume(); child.stderr.setEncoding('utf8').on('data', part => { error += part; });
+ child.done = new Promise(resolve => child.once('close', code => resolve({code,error})));
+ children.push(child); return child;
+ };
+ /** Wait for evidence, not a throughput deadline, while recording the comparison's actual holders. */
+ const observed = async (predicate, label) => {
+ const deadline = Date.now() + 20_000; // budget: hang ceiling for real resource/file handshakes, not a speed assertion.
+ while (!predicate() && Date.now() < deadline) {
+ maximum = Math.max(maximum, entries('holder').filter(row => row.pid === comparison?.pid).length);
+ await new Promise(done => setTimeout(done, 10));
+ }
+ maximum = Math.max(maximum, entries('holder').filter(row => row.pid === comparison?.pid).length);
+ assert.ok(predicate(), label);
+ };
+ /** Read complete append-only records written by native comparison runners. */
+ const order = () => existsSync(log) ? readFileSync(log,'utf8').trim().split('\n').filter(Boolean).map(line => JSON.parse(line)) : [];
+ /** Release only this fixture's blocked work on both assertion success and failure. */
+ const release = name => writeFileSync(join(control,name),'release');
+ try {
+ launchQueue('blocker');
+ await observed(() => existsSync(join(control,'blocker.ready')), 'both private fixture slots are held');
+ comparison = launchQueue('comparison');
+ await observed(() => entries('waiter').some(row => row.pid === comparison.pid), 'the red comparison queues first');
+ const check = launchQueue('check');
+ await observed(() => entries('waiter').some(row => row.pid === check.pid), 'a different item check queues later');
+ assert.equal(entries('waiter').filter(row => row.pid === comparison.pid).length, 1, 'one submit queues only one comparison lease');
+ release('blocker.first');
+ await observed(() => order().length > 0, 'one queued job begins in the released slot');
+ assert.equal(order()[0].name, 'item-check', 'the later independent item check precedes diagnostic work');
+ assert.equal(entries('holder').filter(row => row.pid === comparison.pid).length, 0);
+ release('check.release'); release('blocker.second');
+ await observed(() => order().some(row => row.name !== 'item-check' && row.phase === 'start'), 'the first diagnostic runs after the item check');
+ const first = order().find(row => row.name !== 'item-check' && row.phase === 'start').name;
+ assert.equal(entries('holder').filter(row => row.pid === comparison.pid).length, 1);
+ assert.equal(entries('waiter').filter(row => row.pid === comparison.pid).length, 0, 'no second diagnostic is queued while the first owns a slot');
+ release(first + '.release');
+ await observed(() => order().filter(row => row.name !== 'item-check' && row.phase === 'start').length === 2, 'the second diagnostic starts after the first finishes');
+ const beforeSecond = order().filter(row => row.name !== 'item-check');
+ assert.deepEqual(beforeSecond.slice(0,3).map(row => row.phase), ['start','finish','start']);
+ assert.ok(JSON.parse(readFileSync(join(box.root,'.git/pullboard/main-red.json'),'utf8')).entries[main]['test/' + first], 'the first result is persisted before the next finishes');
+ release('inherited.test.js.release'); release('unrelated.test.js.release');
+ await observed(() => existsSync(join(control,'comparison.result')), 'both diagnostic results finish');
+ assert.equal(maximum, 1, 'one submit never holds two machine slots');
+ assert.deepEqual(JSON.parse(readFileSync(join(control,'comparison.result'),'utf8')), { main, files: [
+ {file:'test/inherited.test.js',result:'red'}, {file:'test/unrelated.test.js',result:'green'},
+ ] });
+ const count = order().length;
+ launchQueue('cached');
+ await observed(() => existsSync(join(control,'cached.result')), 'cached results remain reusable');
+ assert.equal(order().length, count, 'the exact-main cache runs no comparison again');
+ } finally {
+ for (const name of ['blocker.first','blocker.second','check.release','inherited.test.js.release','unrelated.test.js.release']) release(name);
+ for (const child of children) {
+ const result = await child.done;
+ assert.equal(result.code, 0, result.error);
+ }
+ }
+});
+
test('an inherited red reads native spec reporter failure locations [V1]', t => {
const box = fixture(t, { spec: RED_SPEC, source: FAILING_TEST, reporter: 'spec' });
delete box.env.NO_COLOR;
diff --git a/test/submit-compare.test.js b/test/submit-compare.test.js
index 61ed6407..9c8589ea 100644
--- a/test/submit-compare.test.js
+++ b/test/submit-compare.test.js
@@ -181,19 +181,19 @@ test('a shout completes while a submit compares with main [V4,C7,B7]', async t =
await assertRed(box, submission);
});
-test('a red submit reruns its failed files in parallel within the pool [V4,C7,Q4]', async t => {
+test('a red submit reruns its failed files one slot at a time within the pool [V4,C7,Q4]', async t => {
const box = fixture(t, 3, 2);
const submission = launch(box, 'submit', String(box.item));
- await observed(() => events(box).filter(event => event.phase === 'start').length >= 2,
- 'two independent exact-main comparisons start before either is released');
- assert.equal(rows(box.machineQueue, "SELECT token FROM holder WHERE name='gate'").length, 2,
- 'both running comparisons hold actual pool slots');
- await observed(() => rows(box.machineQueue, "SELECT ticket FROM waiter WHERE name='gate'").length === 1,
- 'the third file waits in the actual machine pool');
+ await observed(() => events(box).filter(event => event.phase === 'start').length === 1,
+ 'the first exact-main comparison starts');
+ assert.equal(rows(box.machineQueue, "SELECT token FROM holder WHERE name='gate'").length, 1,
+ 'the running comparison holds one actual pool slot');
+ assert.equal(rows(box.machineQueue, "SELECT ticket FROM waiter WHERE name='gate'").length, 0,
+ 'the remaining files do not flood the machine queue');
const first = events(box).find(event => event.phase === 'start').name;
writeFileSync(join(box.control, first + '.release'), 'release');
- await observed(() => events(box).filter(event => event.phase === 'start').length === 3,
- 'the third file starts after a slot is released');
+ await observed(() => events(box).filter(event => event.phase === 'start').length === 2,
+ 'the second file starts after the first finishes');
assert.equal(JSON.parse(readFileSync(box.cache, 'utf8')).entries[box.main][`test/${first}.test.js`].result,
first === 'b' ? 'red' : 'green', 'the completed result is saved while other files still wait');
for (const name of box.names) writeFileSync(join(box.control, name + '.release'), 'release');
@@ -205,7 +205,7 @@ test('a red submit reruns its failed files in parallel within the pool [V4,C7,Q4
active += event.phase === 'start' ? 1 : -1;
maximum = Math.max(maximum, active);
}
- assert.equal(maximum, 2, 'comparisons overlap without exceeding the configured two slots');
+ assert.equal(maximum, 1, 'one submit leaves the other machine slot available');
assert.equal(active, 0);
assert.deepEqual(JSON.parse(readFileSync(box.cache, 'utf8')).entries[box.main], {
'test/a.test.js': { result: 'green' }, 'test/b.test.js': { result: 'red' }, 'test/c.test.js': { result: 'green' },