testWaitingNamesOtherRunsBriefly

tcmts.cli.budget.test.testWaitingNamesOtherRunsBriefly · #bnsu2lkb · term

import { slotWaits } from "#codebase/tcmts/cli/budget";
import { fakePool, holding } from "#codebase/tcmts/cli/budget/test";
import assert from "node:assert/strict";

export const testWaitingNamesOtherRunsBriefly = async () => {
  const said: string[] = [];
  const { pool, takes } = fakePool();
  const done = slotWaits(
    (l) => said.push(l),
    () => 0,
  ).take(pool, "test definitions of /x/codebase on session/me", 2);
  takes[0]!.onWait({
    holders: [
      holding(process.pid, "tcm test of /x/codebase on session/me"),
      holding(4001, "tcm test of /x/codebase on session/a"),
      holding(4003, "tcm test of /x/codebase on session/a"),
      holding(4004, "test definitions of /x/codebase on session/b"),
      holding(4005, "tcm test of /y/other/codebase"),
      holding(4006, "checks of /x/codebase on session/c"),
      holding(0, "a process starting"),
    ],
    ahead: 0,
    want: 2,
    size: 7,
  });
  // by branch, not path: the pid only where two have the same name, the codebase only if it's another
  assert.deepEqual(said, [
    "waiting for 2 slots: 7 of 7 in use (1 by this run, 1 by session/a (pid 4001), 1 by session/a (pid 4003), 1 by session/b's test definitions, 1 by tcm test of …/other/codebase, 1 by session/c's checks, 1 by a process starting) (TCM_SLOTS sets how many)",
  ]);
  takes[0]!.give();
  await done;
  assert.deepEqual(said.slice(1), ["got 2 slots after 0s"]);
}

uses