testWaitingForSlotsIsSaidBriefly

tcmts.cli.test.e2e.suites.testWaitingForSlotsIsSaidBriefly · #2hbfmsf4 · term

A run waiting for slots says so briefly: when it starts waiting (with what sets how many there are) and how long it took, not each time it waits again soon after; and its summary says how long it waited in all.

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 testWaitingForSlotsIsSaidBriefly = async () => {
  const slots = tempDir("suite slots");
  const log = path.join(tempDir("suite slot log"), "log");
  // one slot for two runs of four suites each: they take turns, each waiting several times
  const dirs = ["one", "two"].map((name) => slowSuites(name, 4, 700));
  const runs = await Promise.all(dirs.map((dir) => runInBudget(dir, slots, 1, log)));
  const waited = runs.filter((r) => /waiting for slots/.test(r.out));
  assert.ok(waited.length, runs.map((r) => r.out).join("\n\n"));
  for (const r of runs) {
    assert.equal(r.status, 0, r.out);
    const lines = r.out.split("\n");
    const waits = lines.filter((l) => /waiting for a slot|got a slot/.test(l));
    // at most when it started waiting and when it got a slot, the hint once
    assert.ok(waits.length <= 2, r.out);
    assert.ok(lines.filter((l) => l.includes("TCM_SLOTS")).length <= 1, r.out);
    // the other run by its codebase's directory, not its whole path nor its pid
    for (const l of waits) {
      assert.doesNotMatch(l, /\(pid \d+\)/);
      for (const dir of dirs) assert.ok(!l.includes(dir), l);
    }
  }
  for (const r of waited) {
    // (on the other run holding the slot, or ahead of it in line)
    assert.match(
      r.out,
      /waiting for a slot: (1 of 1 in use \(1 by [^)]+\)|1 ahead in line)[^\n]* \(TCM_SLOTS sets how many\)\n/,
    );
    assert.match(r.out, /got a slot after [\d.]+s\n/);
    assert.match(r.out, /suites: 4 passed, 0 failed, [\d.]+s waiting for slots\n/);
  }
  assert.deepEqual(fs.readdirSync(slots), []);
}

uses