Skip to content

Commit

Permalink
feat(cli): pad the 'threadId' in test runner logs to align when a hig…
Browse files Browse the repository at this point in the history
…h number of workers / randomize rounds are used
  • Loading branch information
dirkdev98 committed Jun 9, 2023
1 parent 900de5c commit 024813c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/cli/src/compas/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export async function cliExecutor(logger, state) {
state.flags.withLogs = state.flags.withLogs ?? false;

process.env._COMPAS_TEST_WITH_LOGS = String(state.flags.withLogs);
process.env.__COMPAS_TEST_PARALLEL_COUNT = String(parallelCount);
process.env.__COMPAS_TEST_RANDOMIZE_ROUNDS = String(
state.flags.randomizeRounds,
);
refreshEnvironmentCache();

// Make sure to set tests running, so `mainTestFn` is 'disabled'.
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/testing/worker-thread.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setTimeout } from "timers/promises";
import { pathToFileURL } from "url";
import { isMainThread, parentPort, threadId } from "worker_threads";
import { AppError, mainFn, newLogger } from "@compas/stdlib";
import { AppError, environment, mainFn, newLogger } from "@compas/stdlib";
import { loadTestConfig } from "./config.js";
import {
markTestFailuresRecursively,
Expand All @@ -26,12 +26,20 @@ async function main(logger) {
process.exit(1);
}

const totalThreads =
Number(environment.__COMPAS_TEST_PARALLEL_COUNT ?? "1") *
Number(environment.__COMPAS_TEST_RANDOMIZE_ROUNDS ?? "1");
const formattedThreadId = String(threadId).padStart(
String(totalThreads).length,
" ",
);

// Make sure `mainTestFn` is disabled
setAreTestRunning(true);
setTestLogger(
newLogger({
ctx: {
type: `worker-thread(${threadId})`,
type: `worker-thread(${formattedThreadId})`,
},
}),
);
Expand Down

0 comments on commit 024813c

Please sign in to comment.