Fix tasks test

This commit is contained in:
Girish Ramakrishnan
2025-07-18 20:55:46 +02:00
parent 3da1bae826
commit 4f608bdc5f
3 changed files with 14 additions and 12 deletions

View File

@@ -38,10 +38,10 @@ exports = module.exports = {
ETIMEOUT: 'timeout',
// testing
_TASK_IDENTITY: '_identity',
_TASK_CRASH: '_crash',
_TASK_ERROR: '_error',
_TASK_SLEEP: '_sleep'
_TASK_IDENTITY: 'identity',
_TASK_CRASH: 'crash',
_TASK_ERROR: 'error',
_TASK_SLEEP: 'sleep'
};
const assert = require('assert'),
@@ -193,7 +193,7 @@ async function startTask(id, options) {
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
let taskError = null;

View File

@@ -34,10 +34,11 @@ const TASKS = { // indexed by task type
syncDnsRecords: dns.syncDnsRecords,
syncDyndns: dyndns.sync,
_identity: async (arg, progressCallback) => { progressCallback({ percent: 20 }); return arg; },
_error: async (arg, progressCallback) => { progressCallback({ percent: 20 }); throw new Error(`Failed for arg: ${arg}`); },
_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))
// testing
identity: async (arg, progressCallback) => { progressCallback({ percent: 20 }); return arg; },
error: async (arg, progressCallback) => { progressCallback({ percent: 20 }); throw new Error(`Failed for arg: ${arg}`); },
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) {
@@ -117,8 +118,9 @@ async function main() {
await safe(tasks.update(taskId, progress), { debug });
}
debug(`Running task of type ${task.type}`);
const [runError, result] = await safe(TASKS[task.type.replace(/_.*/,'')].apply(null, task.args.concat(progressCallback)));
const taskName = task.type.replace(/_.*/,'');
debug(`Running task of type ${taskName}`);
const [runError, result] = await safe(TASKS[taskName].apply(null, task.args.concat(progressCallback)));
const progress = {
result: result || null,
error: runError ? toTaskError(runError) : null,

View File

@@ -95,7 +95,7 @@ describe('task', function () {
const [error, result] = await safe(tasks.startTask(taskId, {}));
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();
});