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


describe('Processing jobs', ()=> {

  const processMultipleQueue   = Ironium.queue('process-multiple');
  const processPromiseQueue    = Ironium.queue('process-promise');
  const processGeneratorQueue  = Ironium.queue('process-generator');
  const processOnceAQueue      = Ironium.queue('process-once-a');
  const processOnceBQueue      = Ironium.queue('process-once-b');


  describe('with multiple handlers', ()=> {

    // Count how many steps run
    const steps = [];
    before(()=> {
      processMultipleQueue.eachJob((job, callback)=> {
        steps.push('A');
        callback();
      });
      processMultipleQueue.eachJob((job, callback)=> {
        steps.push('B');
        callback();
      });
      processMultipleQueue.eachJob((job, callback)=> {
        steps.push('C');
        callback();
      });
    });

    before(()=> processMultipleQueue.queueJob('job'));
    before(Ironium.runOnce);

    it('should run all steps', ()=> {
      assert.equal(steps.join(''), 'ABC');
    });

  });


  describe('with promises', ()=> {

    // Count how many steps run
    const steps = [];
    before(()=> {
      processPromiseQueue.eachJob(()=> {
        const promise = new Promise(setImmediate);
        return promise
          .then(()=> steps.push('A'))
          .then(()=> steps.push('B'))
          .then(()=> steps.push('C'));
      });
    });

    before(()=> processPromiseQueue.queueJob('job'));
    before(Ironium.runOnce);

    it('should run all steps', ()=> {
      assert.equal(steps.join(''), 'ABC');
    });

  });


  describe('with generator', ()=> {

    // Count how many steps run
    const steps = [];
    before(()=> {
      processGeneratorQueue.eachJob(function*() {
        const one = yield Promise.resolve('A');
        steps.push(one);
        const two = yield (done)=> done(null, 'B');
        steps.push(two);
        const three = yield* (function*() {
          yield setImmediate;
          return 'C';
        })();
        steps.push(three);
      });
    });

    before(()=> processGeneratorQueue.queueJob('job'));
    before(Ironium.runOnce);

    it('should run all steps', ()=> {
      assert.equal(steps.join(''), 'ABC');
    });

  });


  describe('once', ()=> {
    // Count how many steps run
    const steps = [];
    before(()=> {
      // Process A, queue job for B
      // Process B, queue job for A
      // Process A, nothing more
      processOnceAQueue.eachJob(function() {
        steps.push('A');
        if (steps.length == 1)
          return processOnceBQueue.queueJob('job');
        else
          return Promise.resolve();
      });
      processOnceBQueue.eachJob(function() {
        steps.push('B');
        return processOnceAQueue.queueJob('job');
      });
    });

    before(()=> processOnceAQueue.queueJob('job'));
    before(Ironium.runOnce);

    it('should run all jobs to completion', ()=> {
      assert.equal(steps.join(''), 'ABA');
    });
  });

});

<commit_msg>Cleanup handler_tests<commit_after>'use strict';
require('../helpers');
const assert  = require('assert');
const Ironium = require('../..');


describe('Processing jobs', function() {

  const runOnceQueue       = Ironium.queue('run-once');
  const runMultipleQueue   = Ironium.queue('run-multiple');
  const runGeneratorQueue  = Ironium.queue('run-generator');


  describe('with three handlers', function() {

    // Count how many steps run
    const steps = new Set();

    function recordTheStep(step) {
      return function(job, callback) {
        steps.add(step);
        callback();
      };
    }

    before(function() {
      runMultipleQueue.eachJob(recordTheStep('A'));
      runMultipleQueue.eachJob(recordTheStep('B'));
      runMultipleQueue.eachJob(recordTheStep('C'));
      return runMultipleQueue.queueJob('job');
    });
    before(Ironium.runOnce);

    it('should run all three steps', function() {
      assert.equal(steps.size, 3);
    });

  });


  describe('with generator', function() {

    // Count how many steps run
    const steps = new Set();

    function *recordAllSteps() {
      const one = yield Promise.resolve('A');
      steps.add(one);
      const two = yield thunkB;
      steps.add(two);
      const three = yield* yieldC();
      steps.add(three);
    }

    function thunkB(done) {
      done(null, 'B');
    }

    function *yieldC() {
      yield setImmediate;
      return 'C';
    }

    before(function() {
      runGeneratorQueue.eachJob(recordAllSteps);
      return runGeneratorQueue.queueJob('job');
    });
    before(Ironium.runOnce);

    it('should run all three steps', function() {
      assert.equal(steps.size, 3);
    });

  });

});


{'fraction_non_alphanumeric': 0.17435790352892044, 'fraction_numerical': 0.0006264355815410315, 'mean_word_length': 2.593398349587397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '3724462', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1385, 'n_words': 290}