I'm trying to test the following asynchronous function.
async taskComplete() {
this.logger.log('Task Complete');
try {
if (fs.existsSync(`${this.repoDir}/.MENLOLAB_EXIT`)) {
console.log('.MENLOLAB_EXIT Found');
const exitCode = fs.readFileSync(`${this.repoDir}/.MENLOLAB_EXIT`, 'utf8');
let msg = '';
if (exitCode.localeCompare('1')) msg = 'Catchall for general errors';
else if (exitCode.localeCompare('2')) msg = 'Misuse of shell builtins';
else if (exitCode.localeCompare('126')) msg = 'Command invoked cannot execute';
else if (exitCode.localeCompare('127')) msg = '“command not found"';
else if (exitCode.localeCompare('128')) msg = 'Invalid argument to exit';
else if (exitCode.localeCompare('128+n')) msg = 'Fatal error signal “n”';
else if (exitCode.localeCompare('130')) msg = 'Script terminated by Control-C';
else if (exitCode.localeCompare('255\\*')) msg = 'Exit status out of range';
await socket.taskExitCode({ jobID: this.taskData.jobID, exitCode, msg });
} else {
await socket.taskComplete(this.taskData.jobID);
}
} catch (err) {
this.logger.error('Error attempting to send task complete');
return this.taskComplete();
}
return this.destroyTask();
}
My test code is bellow, it keeps timing out after 10000 ms.
1) Test MenloLab Runner - Task Class
Report
TASK.taskComplete()
Generate a Report on Task Completion:
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/yury.stanev/menlolab/runner/test/tasks-tests.js)
From what I'm seeing the taskComplete()
isn't getting called at all. What can be the cause of this behaviour?
describe('Report', () => {
describe('TASK.taskComplete()', () => {
it('Generate a Report on Task Completion', async () => {
try {
const task = new TASK(taskData, () => {});
/* const result = */await task.taskComplete();
// console.log(`${this.repoDir}`);
// shell.exec(`${taskData.cmd}`);
// console.log('HERE ->', result);
// if (fs.existsSync(`${this.repoDir}/.MENLOLAB_EXIT`)) {
// const exitCode = ['1', '2', '126', '127', '128', '128+n', '130', '255\\*'];
// expect(`${this.repoDir}/.MENLOLAB_EXIT`).to.be.a.file().and.not.empty
// .to.be.a.file().with.contents('1' || '2' || '126' || '127' || '128' || '128+n' || '130' || '255');
// } else {
expect(task.destroyTask()).to.be.true;
// }
} catch (err) {
expect(err).to.not.be.undefined;
}
});
});
});
Had to modify the function call to await this.task.taskComplete()
which is strange. The final test code is bellow.
describe('Report', () => {
describe('TASK.taskComplete()', () => {
it('Generate a Report on Task Completion', async () => {
try {
const task = new TASK(taskData, () => {});
await this.task.taskComplete();
if (fs.existsSync(`${this.repoDir}/.MENLOLAB_EXIT`)) {
expect(`${this.repoDir}/.MENLOLAB_EXIT`).to.be.a.file().and.not.empty;
} else {
expect(task.destroyTask()).to.be.true;
}
} catch (err) {
expect(err).to.not.be.undefined;
}
});
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.