<commit_before>var SimpleScheduler = require('../lib/scheduler/simple-scheduler.js');
var AppSpec = require('../lib/worker/app-spec.js');
var sinon = require('sinon');
var Q = require('q');

var scheduler = new SimpleScheduler();
var appSpec = new AppSpec("/var/shiny-www/testA/", "jalle6", "", "/tmp", {})

describe('SimpleScheduler', function(){
  describe('#acquireWorker_p()', function(){
    it('should initially create a new worker.', function(done){
      //check that we're starting off with no workers.
      Object.keys(scheduler.$workers).should.be.empty;

      //request a worker
      scheduler.acquireWorker_p(appSpec)
      .then(function(wh){ wh.kill(); })
      .then(done, done).done();

      //check that exactly one app had workers created
      Object.keys(scheduler.$workers).should.have.length(1);

      //check that exactly one worker has been created for this app's key.
      var relWorkers = scheduler.$workers[appSpec.getKey()];
      Object.keys(relWorkers).should.have.length(1);

      //check that the worker has the necessary fields created.
      var worker = relWorkers[Object.keys(relWorkers)[0]];
      worker.should.have.keys(['data', 'promise']);
      Object.keys(worker.data).should.have.length(2);
    }),
    it('should not create a new worker for requests to the same app.', function(done){
      //check that we have the one worker left from the previous app
      Object.keys(scheduler.$workers).should.have.length(1);

      //request a worker for the new app
      scheduler.acquireWorker_p(appSpec)
      .then(function(wh){ wh.kill(); })
      .then(done, done).done();

      //check that one additional app had workers created
      Object.keys(scheduler.$workers).should.have.length(1);

      //check that exactly one worker has been created for this app's key.
      var relWorkers = scheduler.$workers[appSpec.getKey()];
      Object.keys(relWorkers).should.have.length(1);

      //check that the worker has the necessary fields created.
      var worker = relWorkers[Object.keys(relWorkers)[0]];
      worker.should.have.keys(['data', 'promise']);
    }),
    it('should create a new worker for a modified/new app.', function(done){
      //check that we have the one worker left from the previous app
      Object.keys(scheduler.$workers).should.have.length(1);

      //modify the settings of the app slightly.
      appSpec.settings = {a:1};

      //request a worker for the new app
      scheduler.acquireWorker_p(appSpec)
      .then(function(wh){ wh.kill(); })
      .then(done, done).done();

      //check that one additional app had workers created
      Object.keys(scheduler.$workers).should.have.length(2);

      //check that exactly one worker has been created for this app's key.
      var relWorkers = scheduler.$workers[appSpec.getKey()];
      Object.keys(relWorkers).should.have.length(1);

      //check that the worker has the necessary fields created.
      var worker = relWorkers[Object.keys(relWorkers)[0]];
      worker.should.have.keys(['data', 'promise']);
    })
  })

})<commit_msg>Create placeholder for test.<commit_after>var SimpleScheduler = require('../lib/scheduler/simple-scheduler.js');
var AppSpec = require('../lib/worker/app-spec.js');
var sinon = require('sinon');
var Q = require('q');

var scheduler = new SimpleScheduler();
var appSpec = new AppSpec("/var/shiny-www/testA/", "jalle6", "", "/tmp", {})

describe('SimpleScheduler', function(){
  describe('#acquireWorker_p()', function(){
    it('should initially create a new worker.', function(done){
      //check that we're starting off with no workers.
      Object.keys(scheduler.$workers).should.be.empty;

      //request a worker
      scheduler.acquireWorker_p(appSpec)
      .then(function(wh){ wh.kill(); })
      .then(done, done).done();

      //check that exactly one app had workers created
      Object.keys(scheduler.$workers).should.have.length(1);

      //check that exactly one worker has been created for this app's key.
      var relWorkers = scheduler.$workers[appSpec.getKey()];
      Object.keys(relWorkers).should.have.length(1);

      //check that the worker has the necessary fields created.
      var worker = relWorkers[Object.keys(relWorkers)[0]];
      worker.should.have.keys(['data', 'promise']);
      Object.keys(worker.data).should.have.length(2);
    }),
    it('should not create a new worker for requests to the same app.', function(done){
      //check that we have the one worker left from the previous app
      Object.keys(scheduler.$workers).should.have.length(1);

      //request a worker for the new app
      scheduler.acquireWorker_p(appSpec)
      .then(function(wh){ wh.kill(); })
      .then(done, done).done();

      //check that one additional app had workers created
      Object.keys(scheduler.$workers).should.have.length(1);

      //check that exactly one worker has been created for this app's key.
      var relWorkers = scheduler.$workers[appSpec.getKey()];
      Object.keys(relWorkers).should.have.length(1);

      //check that the worker has the necessary fields created.
      var worker = relWorkers[Object.keys(relWorkers)[0]];
      worker.should.have.keys(['data', 'promise']);
    }),
    it('should create a new worker for a modified/new app.', function(done){
      //check that we have the one worker left from the previous app
      Object.keys(scheduler.$workers).should.have.length(1);

      //modify the settings of the app slightly.
      appSpec.settings = {a:1};

      //request a worker for the new app
      scheduler.acquireWorker_p(appSpec)
      .then(function(wh){ wh.kill(); })
      .then(done, done).done();

      //check that one additional app had workers created
      Object.keys(scheduler.$workers).should.have.length(2);

      //check that exactly one worker has been created for this app's key.
      var relWorkers = scheduler.$workers[appSpec.getKey()];
      Object.keys(relWorkers).should.have.length(1);

      //check that the worker has the necessary fields created.
      var worker = relWorkers[Object.keys(relWorkers)[0]];
      worker.should.have.keys(['data', 'promise']);
    }),
    it('should not surpass the MAX_REQUESTS directive.')
  })

})
{'fraction_non_alphanumeric': 0.14000964475164765, 'fraction_numerical': 0.004500884102234368, 'mean_word_length': 3.209742895805142, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1845566', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1776, 'n_words': 509}