Fix tasks test
This commit is contained in:
+5
-5
@@ -38,10 +38,10 @@ exports = module.exports = {
|
|||||||
ETIMEOUT: 'timeout',
|
ETIMEOUT: 'timeout',
|
||||||
|
|
||||||
// testing
|
// testing
|
||||||
_TASK_IDENTITY: '_identity',
|
_TASK_IDENTITY: 'identity',
|
||||||
_TASK_CRASH: '_crash',
|
_TASK_CRASH: 'crash',
|
||||||
_TASK_ERROR: '_error',
|
_TASK_ERROR: 'error',
|
||||||
_TASK_SLEEP: '_sleep'
|
_TASK_SLEEP: 'sleep'
|
||||||
};
|
};
|
||||||
|
|
||||||
const assert = require('assert'),
|
const assert = require('assert'),
|
||||||
@@ -193,7 +193,7 @@ async function startTask(id, options) {
|
|||||||
return task.result;
|
return task.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.ok(sudoError, 'sudo should have errorred because task did not complete!');
|
assert.ok(sudoError, 'sudo should have errored because task did not complete!');
|
||||||
|
|
||||||
// taskworker.sh forwards the exit code of the actual worker. It's either a raw signal number OR the exit code
|
// taskworker.sh forwards the exit code of the actual worker. It's either a raw signal number OR the exit code
|
||||||
let taskError = null;
|
let taskError = null;
|
||||||
|
|||||||
+8
-6
@@ -34,10 +34,11 @@ const TASKS = { // indexed by task type
|
|||||||
syncDnsRecords: dns.syncDnsRecords,
|
syncDnsRecords: dns.syncDnsRecords,
|
||||||
syncDyndns: dyndns.sync,
|
syncDyndns: dyndns.sync,
|
||||||
|
|
||||||
_identity: async (arg, progressCallback) => { progressCallback({ percent: 20 }); return arg; },
|
// testing
|
||||||
_error: async (arg, progressCallback) => { progressCallback({ percent: 20 }); throw new Error(`Failed for arg: ${arg}`); },
|
identity: async (arg, progressCallback) => { progressCallback({ percent: 20 }); return arg; },
|
||||||
_crash: (arg) => { throw new Error(`Crashing for arg: ${arg}`); }, // the test looks for this debug string in the log file
|
error: async (arg, progressCallback) => { progressCallback({ percent: 20 }); throw new Error(`Failed for arg: ${arg}`); },
|
||||||
_sleep: async (arg) => await timers.setTimeout(parseInt(arg, 10))
|
crash: (arg) => { throw new Error(`Crashing for arg: ${arg}`); }, // the test looks for this debug string in the log file
|
||||||
|
sleep: async (arg) => await timers.setTimeout(parseInt(arg, 10))
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.argv.length !== 4) {
|
if (process.argv.length !== 4) {
|
||||||
@@ -117,8 +118,9 @@ async function main() {
|
|||||||
await safe(tasks.update(taskId, progress), { debug });
|
await safe(tasks.update(taskId, progress), { debug });
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(`Running task of type ${task.type}`);
|
const taskName = task.type.replace(/_.*/,'');
|
||||||
const [runError, result] = await safe(TASKS[task.type.replace(/_.*/,'')].apply(null, task.args.concat(progressCallback)));
|
debug(`Running task of type ${taskName}`);
|
||||||
|
const [runError, result] = await safe(TASKS[taskName].apply(null, task.args.concat(progressCallback)));
|
||||||
const progress = {
|
const progress = {
|
||||||
result: result || null,
|
result: result || null,
|
||||||
error: runError ? toTaskError(runError) : null,
|
error: runError ? toTaskError(runError) : null,
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ describe('task', function () {
|
|||||||
|
|
||||||
const [error, result] = await safe(tasks.startTask(taskId, {}));
|
const [error, result] = await safe(tasks.startTask(taskId, {}));
|
||||||
if (!error) throw new Error('expecting task to fail');
|
if (!error) throw new Error('expecting task to fail');
|
||||||
expect(error.message).to.be('Failed for arg: ping');
|
expect(error.message).to.be('Task crashed. Failed for arg: ping');
|
||||||
expect(result).to.not.be.ok();
|
expect(result).to.not.be.ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user