<commit_before>import MochaReflow from './mocha-reflow';
import threadPool from './thread-pool'
import path from 'path'

const executeMatrix = function(matrix, config) {
  const {
    mocha: mochaConfig,
    numberOfThreads,
  } = config;

  const pool = threadPool({
    workerPath: path.join(__dirname, './worker.js'),
    threadsToSpawn: numberOfThreads,
  });

  const sendToPool = tree => pool.send({tree, mochaConfig})
  matrix.forEach(sendToPool);
  let failures = 0;

  pool
    .on('done', function(job, jobFailures) {
      failures += jobFailures;
    })
    .on('error', function(job, error) {
      throw new Error('Job errored:', error)
    })
    .on('finished', function() {
      console.log('Everything done, shutting down the thread pool.');
      console.log(`${failures} total errors.`);
      pool.killAll();
      process.exit(failures)
    });

  return pool
}

export default executeMatrix
<commit_msg>limit thread number to number of flows<commit_after>import MochaReflow from './mocha-reflow';
import threadPool from './thread-pool'
import path from 'path'

const executeMatrix = function(matrix, config) {
  const {
    mocha: mochaConfig,
    numberOfThreads,
  } = config;

  const pool = threadPool({
    workerPath: path.join(__dirname, './worker.js'),
    threadsToSpawn: Math.min(numberOfThreads, matrix.length),
  });

  const sendToPool = tree => pool.send({tree, mochaConfig})
  matrix.forEach(sendToPool);
  let failures = 0;

  pool
    .on('done', function(job, jobFailures) {
      failures += jobFailures;
    })
    .on('error', function(job, error) {
      throw new Error('Job errored:', error)
    })
    .on('finished', function() {
      console.log('Everything done, shutting down the thread pool.');
      console.log(`${failures} total errors.`);
      pool.killAll();
      process.exit(failures)
    });

  return pool
}

export default executeMatrix

{'fraction_non_alphanumeric': 0.13918067226890757, 'fraction_numerical': 0.0010504201680672268, 'mean_word_length': 3.4302325581395348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7570832', 'n_tokens_mistral': 601, 'n_tokens_neox': 588, 'n_words': 149}