<commit_before>'use strict';
const assert  = require('assert');
const fork    = require('child_process').fork;
const Ironium = require('../..');


const isMocha = !!global.describe;

if (isMocha)
  runTestSuite();
else
  runChildProcess();


function runTestSuite() {

  describe('Child process', function() {

    let child;
    const steps = [];

    before(function() {
      Ironium.configure({ concurrency: 1 });
    });

    before(function(done) {
      child = fork(module.filename, { env: { NODE_ENV: 'test', DEBUG: process.env.DEBUG } });

      child.on('message', function(step) {
        steps.push(step);
      });

      child.on('exit', function(code) {
        done(code ? new Error(`Exited with code ${code}`) : null);
      });
    });

    it('should run regular job', function() {
      assert(steps.indexOf('regular') >= 0);
    });

    it('should run three duplicate jobs', function() {
      const duplicates = steps.filter(function(step) { return step === 'duplicate'; });
      assert.equal(duplicates.length, 3);
    });

    it('should run delayed job', function() {
      assert(steps.indexOf('delayed') >= 0);
    });

    it('should run three failed jobs', function() {
      const failed = steps.filter(function(step) { return step == 'failed'; });
      assert.equal(failed.length, 3);
    });

    after(function() {
      child.kill();
    });

  });
}


function runChildProcess() {

  const Bluebird  = require('bluebird');
  const Ironium   = require('../..');


  // Regular job: queued once, execute once
  Ironium.eachJob('regular', function() {
    process.send('regular');

    return Ironium.queueJob('duplicate', 'job')
      .then(function() {
        return Ironium.queueJob('duplicate', 'job');
      })
      .then(function() {
        return Ironium.queueJob('duplicate', 'job');
      })
      .then(function() {
        return Ironium.queueJob('delayed', 'job');
      });<commit_msg>Fix brace style.<commit_after>'use strict';
const assert  = require('assert');
const fork    = require('child_process').fork;
const Ironium = require('../..');


const isMocha = !!global.describe;

if (isMocha)
  runTestSuite();
else
  runChildProcess();


function runTestSuite() {

  describe('Child process', function() {

    let child;
    const steps = [];

    before(function() {
      Ironium.configure({ concurrency: 1 });
    });

    before(function(done) {
      child = fork(module.filename, { env: { NODE_ENV: 'test', DEBUG: process.env.DEBUG } });

      child.on('message', function(step) {
        steps.push(step);
      });

      child.on('exit', function(code) {
        done(code ? new Error(`Exited with code ${code}`) : null);
      });
    });

    it('should run regular job', function() {
      assert(steps.indexOf('regular') >= 0);
    });

    it('should run three duplicate jobs', function() {
      const duplicates = steps.filter(step => step === 'duplicate');
      assert.equal(duplicates.length, 3);
    });

    it('should run delayed job', function() {
      assert(steps.indexOf('delayed') >= 0);
    });

    it('should run three failed jobs', function() {
      const failed = steps.filter(step => step == 'failed');
      assert.equal(failed.length, 3);
    });

    after(function() {
      child.kill();
    });

  });
}


function runChildProcess() {

  const Bluebird  = require('bluebird');
  const Ironium   = require('../..');


  // Regular job: queued once, execute once
  Ironium.eachJob('regular', function() {
    process.send('regular');

    return Ironium.queueJob('duplicate', 'job')
      .then(function() {
        return Ironium.queueJob('duplicate', 'job');
      })
      .then(function() {
        return Ironium.queueJob('duplicate', 'job');
      })
      .then(function() {
        return Ironium.queueJob('delayed', 'job');
      });
{'fraction_non_alphanumeric': 0.17895285230528785, 'fraction_numerical': 0.0026048450117218025, 'mean_word_length': 2.878787878787879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5308292', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1128, 'n_words': 256}