Skip to content

Commit

Permalink
#178 Remove jobList and workerList after tests.
Browse files Browse the repository at this point in the history
Put these in test-tmp during TESTING.
  • Loading branch information
pmeijer committed Feb 26, 2015
1 parent b0887d6 commit c601bc2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/middleware/executor/Executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ define(['logManager',
],
function (logManager, fs, path, child_process, bufferEqual, DataStore, JobInfo, WorkerInfo) {
'use strict';

var jobListDBFile = TESTING ? 'test-tmp/jobList.nedb' : 'jobList.nedb';
var workerListDBFile = TESTING ? 'test-tmp/workerList.nedb' : 'workerList.nedb';
var logger = logManager.create('REST-Executor'); //how to define your own logger which will use the global settings

var jobList = new DataStore({filename: 'jobList.nedb', autoload: true});
var jobList = new DataStore({filename: jobListDBFile, autoload: true});
jobList.ensureIndex({fieldName: 'hash', unique: true}, function (err) {
if (err) {
console.error(err);
Expand All @@ -33,7 +34,7 @@ define(['logManager',

var workerRefreshInterval = 5 * 1000;
// worker = { clientId:, lastSeen: }
var workerList = new DataStore({filename: 'workerList.nedb', autoload: true});
var workerList = new DataStore({filename: workerListDBFile, autoload: true});
var workerTimeout = function () {
if (process.uptime() < workerRefreshInterval / 1000 * 5) {
return;
Expand Down
11 changes: 11 additions & 0 deletions test/middleware/executor/Executor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require('../../_globals.js');

var agent = require('superagent').agent(),
should = require('chai').should(),
fs = require('fs'),
server,
serverBaseUrl;

Expand All @@ -16,6 +17,16 @@ describe('Executor', function () {

afterEach(function (done) {
server.stop(done);
try {
fs.unlinkSync('test-tmp/jobList.nedb');
} catch (err) {
//console.log(err);
}
try {
fs.unlinkSync('test-tmp/workerList.nedb');
} catch (err) {
//console.log(err);
}
});

it('should return 200 at rest/executor/worker/ with enableExecutor=true', function (done) {
Expand Down
45 changes: 44 additions & 1 deletion test/middleware/executor/ExecutorClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
require('../../_globals.js');

var requirejs = require('requirejs'),
fs = require('fs'),
should = require('chai').should(),
ExecutorClient = requirejs('executor/ExecutorClient'),
executorClient,
server,
serverBaseUrl;
// TODO: How to specify the nedb paths for jobList and workerList?

describe('ExecutorClient', function () {
'use strict';

Expand All @@ -37,6 +38,16 @@ describe('ExecutorClient', function () {

after(function (done) {
server.stop(done);
try {
fs.unlinkSync('test-tmp/jobList.nedb');
} catch (err) {
//console.log(err);
}
try {
fs.unlinkSync('test-tmp/workerList.nedb');
} catch (err) {
//console.log(err);
}
});

it('getWorkersInfo should return empty object', function (done) {
Expand Down Expand Up @@ -92,6 +103,38 @@ describe('ExecutorClient', function () {
});
});

it('updateJob with SUCCESS followed by getInfo should return SUCCESS in jobInfo', function (done) {
var jobInfo = {
hash: '88804f10a36aa4214f5b0095ba8099e729a10f46'
};
executorClient.createJob(jobInfo, function (err, res) {
var createTime;
if (err) {
done(err);
return;
}
should.equal(typeof res, 'object');
createTime = res.createTime;
should.equal(res.status, 'CREATED');
should.equal(typeof createTime, 'string');
jobInfo.status = 'SUCCESS';
executorClient.updateJob(jobInfo, function (err) {
if (err) {
done(err);
}
executorClient.getInfo(jobInfo.hash, function (err, res) {
if (err) {
done(err);
return;
}
should.equal(typeof res, 'object');
should.equal(res.createTime, createTime);
should.equal(res.status, 'SUCCESS');
done();
});
});
});
});
//it('getInfoByStatus SUCCESS should succeed', function (done) {
// executorClient.getInfoByStatus('SUCCESS', function(err, res) {
// should.equal(err, null);
Expand Down

0 comments on commit c601bc2

Please sign in to comment.