<commit_before>/* eslint no-underscore-dangle: 0 */
const chai = require('chai');
const { assert } = chai;

/**
 * Spec the basic job functions
 */
describe('Base Job Spec', () => {
  it('Should trigger hook beforeJobCreate function', (done) => {
    let beforeCreate = false;
    global.beforeJobCreate = () => {
      beforeCreate = true;
    };

    global.singleJob = () => {
      assert.equal(beforeCreate, true);
      return Promise.resolve().then(() => done());
    };
    Hook
      .create('queue1', {
        runs: 'singleJob',
        data: {
          bar: 'foo'
        }
      });
  });

  it('Should trigger hook afterJobCreate function', (done) => {
    let afterCreate = false;
    global.afterJobCreate = () => {
      afterCreate = true;
      done();
    };

    global.doop = null;
    Hook
      .create('queue1', {
        runs: 'doop',
        data: {
          bar: 'foo'
        }
      });
  });

  it('Should only allow a string as the first argument (queue)', (done) => {
    assert.equal(Hook.create(), null);
    assert.equal(Hook.create(1337), null);
    done();
  });

  it('Should only allow an object as the second argument (options)', (done) => {
    assert.equal(Hook.create('queue1', 1337), null);
    done();
  });

  it('Should run a single job', (done) => {
    global.singleJob = function singleJob() {
      done();
    };

    Hook
      .create('queue1', {
        runs: 'singleJob',
      });
  });

  // it('Should bind the Job class to the job', (done) => {
  //   global.singleJob = function singleJob() {
  //     assert.equal(this.constructor.name, 'Job');
  //     done();
  //   };
  //
  //   Hook.create('queue1', {
  //     runs: 'singleJob',
  //   });
  // });

  it('Should NOT bind the Job class to the job when noBind option is enabled', (done) => {
    global.singleJob = function singleJob() {
      console.log(this.constructor.name);
      assert.equal(this.constructor.name, 'Object');
      done();
    };

    Hook.create('queue1', {
      runs: 'singleJob',
      noBind: true,
    });
  });

  it('Should run a single job and pass data to it', (done) => {
    global.singleJob = function singleJob(job) {
      assert.equal(job.data.foo, 'bar');
      done();
    };

    Hook
      .create('queue1', {
        runs: 'singleJob',
        data: {
          foo: 'bar',
        },
      });
  });

  it('Should run relay jobs', (done) => {
    let count = 0;
    global.relayJob = function relayJob() {
      count++;
    };

    global.relayJobEnd = function relayJobEnd() {
      assert.equal(count, 3);

      return Promise.resolve().then(() => done());
    };

    Hook.create('queue2', {
      runs: ['relayJob', 'relayJob', 'relayJob', 'relayJobEnd'],
    });
  });

  it('Should run a shit load of single jobs', (done) => {
    let count = 0;
    global.singleJob = function singleJob() {
      count++;

      if (count === 1000) {
        done();
        return count;
      }
      return count;
    };

    for (var i = 0; i < 1000; i++) {
      Hook.create('queue1', {
        runs: 'singleJob',
        data: i,
      });
    }
  });

  it('Should run a shit load of relay jobs', (done) => {
    let endCount = 0;
    global.relayJob = function relayJob() {
      return Promise.resolve();
    };

    global.relayJobEnd = function relayJobEnd() {
      endCount++;
      if (endCount === 100) {
        return Promise.resolve(endCount).then(() => done());
      }

      return Promise.resolve(endCount);
    };

    for (var i = 0; i < 100; i++) {
      Hook.create('queue1', {
        runs: ['relayJob', 'relayJob', 'relayJob', 'relayJobEnd'],
        data: i,
      });
    }
  });


  it('Should run relay jobs whilst passing new data along', (done) => {
    let count = 0;

    global.relayJob = function relayJob(job) {
      assert.equal(job.data.count, count);
      count++;
      return Promise.resolve({ count });
    };

    global.relayJobEnd = function relayJobEnd(job) {
      assert.equal(job.data.count, count);

      return Promise.resolve().then(done);
    };

    Hook.create('queue1', {
      runs: ['relayJob', 'relayJob', 'relayJob', 'relayJobEnd'],
      data: {
        count: 0,<commit_msg>increased number of jobs created for relay test<commit_after>/* eslint no-underscore-dangle: 0 */
const chai = require('chai');
const { assert } = chai;

/**
 * Spec the basic job functions
 */
describe('Base Job Spec', () => {
  it('Should trigger hook beforeJobCreate function', (done) => {
    let beforeCreate = false;
    global.beforeJobCreate = () => {
      beforeCreate = true;
    };

    global.singleJob = () => {
      assert.equal(beforeCreate, true);
      return Promise.resolve().then(() => done());
    };
    Hook
      .create('queue1', {
        runs: 'singleJob',
        data: {
          bar: 'foo'
        }
      });
  });

  it('Should trigger hook afterJobCreate function', (done) => {
    let afterCreate = false;
    global.afterJobCreate = () => {
      afterCreate = true;
      done();
    };

    global.doop = null;
    Hook
      .create('queue1', {
        runs: 'doop',
        data: {
          bar: 'foo'
        }
      });
  });

  it('Should only allow a string as the first argument (queue)', (done) => {
    assert.equal(Hook.create(), null);
    assert.equal(Hook.create(1337), null);
    done();
  });

  it('Should only allow an object as the second argument (options)', (done) => {
    assert.equal(Hook.create('queue1', 1337), null);
    done();
  });

  it('Should run a single job', (done) => {
    global.singleJob = function singleJob() {
      done();
    };

    Hook
      .create('queue1', {
        runs: 'singleJob',
      });
  });

  // it('Should bind the Job class to the job', (done) => {
  //   global.singleJob = function singleJob() {
  //     assert.equal(this.constructor.name, 'Job');
  //     done();
  //   };
  //
  //   Hook.create('queue1', {
  //     runs: 'singleJob',
  //   });
  // });

  it('Should NOT bind the Job class to the job when noBind option is enabled', (done) => {
    global.singleJob = function singleJob() {
      console.log(this.constructor.name);
      assert.equal(this.constructor.name, 'Object');
      done();
    };

    Hook.create('queue1', {
      runs: 'singleJob',
      noBind: true,
    });
  });

  it('Should run a single job and pass data to it', (done) => {
    global.singleJob = function singleJob(job) {
      assert.equal(job.data.foo, 'bar');
      done();
    };

    Hook
      .create('queue1', {
        runs: 'singleJob',
        data: {
          foo: 'bar',
        },
      });
  });

  it('Should run relay jobs', (done) => {
    let count = 0;
    global.relayJob = function relayJob() {
      count++;
    };

    global.relayJobEnd = function relayJobEnd() {
      assert.equal(count, 3);

      return Promise.resolve().then(() => done());
    };

    Hook.create('queue2', {
      runs: ['relayJob', 'relayJob', 'relayJob', 'relayJobEnd'],
    });
  });

  it('Should run a shit load of single jobs', (done) => {
    let count = 0;
    global.singleJob = function singleJob() {
      count++;

      if (count === 1000) {
        done();
        return count;
      }
      return count;
    };

    for (var i = 0; i < 1000; i++) {
      Hook.create('queue1', {
        runs: 'singleJob',
        data: i,
      });
    }
  });

  it('Should run a shit load of relay jobs', (done) => {
    let endCount = 0;
    global.relayJob = function relayJob() {
      return Promise.resolve();
    };

    global.relayJobEnd = function relayJobEnd() {
      endCount++;
      if (endCount === 100) {
        return Promise.resolve(endCount).then(() => done());
      }

      return Promise.resolve(endCount);
    };

    for (var i = 0; i < 500; i++) {
      Hook.create('queue1', {
        runs: ['relayJob', 'relayJob', 'relayJob', 'relayJobEnd'],
        data: i,
      });
    }
  });


  it('Should run relay jobs whilst passing new data along', (done) => {
    let count = 0;

    global.relayJob = function relayJob(job) {
      assert.equal(job.data.count, count);
      count++;
      return Promise.resolve({ count });
    };

    global.relayJobEnd = function relayJobEnd(job) {
      assert.equal(job.data.count, count);

      return Promise.resolve().then(done);
    };

    Hook.create('queue1', {
      runs: ['relayJob', 'relayJob', 'relayJob', 'relayJobEnd'],
      data: {
        count: 0,
{'fraction_non_alphanumeric': 0.17278976060677886, 'fraction_numerical': 0.009954965631666271, 'mean_word_length': 2.165416354088522, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, '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': 4, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2984295', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2666, 'n_words': 652}