testSlotsSayWhatTheyreFor

tcmts.cli.running.test.testSlotsSayWhatTheyreFor · #j7isyy74 · term

A slot taken saying what it's for (a suite) is read back with its holder as held, with what it's for; given back, it isn't.

import { slotPool } from "#codebase/tcmts/cli/budget";
import { slotsNow } from "#codebase/tcmts/cli/running";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

export const testSlotsSayWhatTheyreFor = async () => {
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), "tcm slots for "));
  const was = process.env.TCM_SLOTS_DIR;
  process.env.TCM_SLOTS_DIR = dir;
  try {
    const release = await slotPool(dir, 2).take(
      "tcm test of /x/codebase on main",
      undefined,
      1,
      "cli.test.e2e.studio.testStudio",
    );
    const held = slotsNow().held;
    assert.equal(held.length, 1);
    assert.deepEqual(
      [held[0]!.pid, held[0]!.what, held[0]!.detail],
      [process.pid, "tcm test of /x/codebase on main", "cli.test.e2e.studio.testStudio"],
    );
    release();
    assert.equal(slotsNow().held.length, 0);
  } finally {
    if (was === undefined) delete process.env.TCM_SLOTS_DIR;
    else process.env.TCM_SLOTS_DIR = was;
    fs.rmSync(dir, { recursive: true, force: true });
  }
}

uses