/**
 * Created by TalhaAkkas on 12/08/15.
 */

var should = require('should');
var threads = require('../threads');

var workerPath = __dirname + "/TestWorker.js";


var utils = require('../../Utils/utils');
var WaitingFunction = utils.WaitingFunction;
threads.setMaxWaitingTime(750);
describe('Threads Tests', function () {
	it('should return from job when finished', function (done) {
		var func = new WaitingFunction();
		for(var i = 0; i < 5; i++){
			threads.pushJob({path:workerPath, data:1000, usageLimit:2}, func.getCbToWait());
		}
		func.cb = function(){
			done();
		}
	});

	it('should return cancel job for when', function (done) {
		var func = new WaitingFunction();
		for(var i = 0; i < 5; i++){
			threads.pushJob({path:workerPath, data:{timeout:5000}, usageLimit:2}, func.getCbToWait());
		}
		func.cb = function(){
			//console.log(func);
			for(var key in func.waitingList){
				//console.log(func.waitingList[key].args);
				func.waitingList[key].args.length.should.equal(1);
			}
			done();
		}
	});
	it('should return not', function (done) {
		var func = new WaitingFunction();
		for(var i = 0; i < 5; i++){
			threads.pushJob({path:workerPath, data:{timeout:5000}, usageLimit:2}, func.getCbToWait());
		}
		func.cb = function(){
			//console.log(func);
			for(var key in func.waitingList){
				//console.log(func.waitingList[key].args);
				func.waitingList[key].args.length.should.equal(1);
			}
			done();
		}
	});

});