Skip to content

Commit

Permalink
Fix #302 - allow the user to specify the number of threads with -j
Browse files Browse the repository at this point in the history
  • Loading branch information
atilaneves committed Aug 2, 2023
1 parent b0e0809 commit 40cedb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion subpackages/runner/source/unit_threaded/runner/options.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct Options {
bool stackTraces;
bool showChrono;
bool quiet;
size_t numJobs;
}

/**
Expand All @@ -27,6 +28,7 @@ auto getOptions(string[] args) {
import std.stdio: writeln;
import std.random: unpredictableSeed;
import std.getopt: getopt, defaultGetoptPrinter;
import std.parallelism: totalCPUs;

bool single;
bool debugOutput;
Expand All @@ -38,6 +40,7 @@ auto getOptions(string[] args) {
bool stackTraces;
bool showChrono;
bool quiet;
size_t numJobs = totalCPUs - 1;

auto helpInfo =
getopt(args,
Expand All @@ -50,6 +53,7 @@ auto getOptions(string[] args) {
"trace|t", "enable stack traces", &stackTraces,
"chrono|c", "Print execution time per test", &showChrono,
"q|quiet", "Only print information about failing tests", &quiet,
"j|jobs", "Number of threads to use", &numJobs,
);

if(helpInfo.helpWanted) {
Expand All @@ -67,5 +71,5 @@ auto getOptions(string[] args) {

immutable exit = help || list;
return Options(!single, args[1..$], debugOutput, list, exit, forceEscCodes,
random, seed, stackTraces, showChrono, quiet);
random, seed, stackTraces, showChrono, quiet, numJobs);
}
2 changes: 1 addition & 1 deletion subpackages/runner/source/unit_threaded/runner/testsuite.d
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private:

if (_options.multiThreaded) {
// use a dedicated task pool with non-daemon worker threads
auto taskPool = new TaskPool;
auto taskPool = new TaskPool(_options.numJobs);
_failures = reduce!((a, b) => a ~ b)(_failures, taskPool.amap!runTest(tests));
taskPool.finish(/*blocking=*/false);
} else {
Expand Down

0 comments on commit 40cedb3

Please sign in to comment.