testSuiteSlotsAreSharedByEveryRun

tcmts.cli.test.e2e.suites.testSuiteSlotsAreSharedByEveryRun · #s3mnpoh7 · term

Every tcm running suites on a machine takes them from one budget (TCM_SUITE_SLOTS, in TCM_SLOTS_DIR): two tcm test runs of two codebases at once never have more suites running between them than it allows, and one waiting says so, and on what.

import { tempDir } from "#codebase/tcmts/cli/test/e2e/harness";
import { runInBudget, slowSuites } from "#codebase/tcmts/cli/test/e2e/suites";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export const testSuiteSlotsAreSharedByEveryRun = async () => {
  const slots = tempDir("suite slots");
  const log = path.join(tempDir("suite slot log"), "log");
  const dirs = ["one", "two"].map((name) => slowSuites(name, 4, 700));
  const runs = await Promise.all(dirs.map((dir) => runInBudget(dir, slots, 2, log)));
  for (const r of runs) {
    assert.equal(r.status, 0, r.out);
    assert.match(r.out, /suites: 4 passed, 0 failed(, [\d.]+s waiting for slots)?\n/);
  }
  // at most two at once, from both runs together (an end before a start at the same moment)
  const events = fs
    .readFileSync(log, "utf8")
    .trim()
    .split("\n")
    .map((l) => l.split(" ") as [string, "+" | "-", string])
    .sort((a, b) => Number(a[0]) - Number(b[0]) || (a[1] === "-" ? -1 : 1));
  assert.equal(events.length, 16);
  let running = 0;
  let most = 0;
  for (const [, e] of events) most = Math.max(most, (running += e === "+" ? 1 : -1));
  assert.equal(most, 2, events.map((e) => e.join(" ")).join("\n"));
  // the run that waited said so: for what, and on whom (the other codebase, by its directory)
  assert.match(
    runs.map((r) => r.out).join("\n"),
    /waiting for a slot: 2 of 2 in use \([^)]*\d by tcm test of …\/[^)]+\)/,
  );
  assert.deepEqual(fs.readdirSync(slots), []);
}

uses