From 4f608bdc5f40b1cf4b57f031bd57be4e94cea434 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 18 Jul 2025 20:55:46 +0200 Subject: [PATCH] Fix tasks test --- src/tasks.js | 10 +++++----- src/taskworker.js | 14 ++++++++------ src/test/tasks-test.js | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/tasks.js b/src/tasks.js index 03d7f6142..63bd9dc84 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -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; diff --git a/src/taskworker.js b/src/taskworker.js index acc0fce4c..f4157e919 100755 --- a/src/taskworker.js +++ b/src/taskworker.js @@ -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, diff --git a/src/test/tasks-test.js b/src/test/tasks-test.js index 7e72798c6..f431a25cd 100644 --- a/src/test/tasks-test.js +++ b/src/test/tasks-test.js @@ -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(); });