Skip to content

Commit

Permalink
chore: improve process exit handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rorlic committed Apr 4, 2024
1 parent 91d9290 commit 58078cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,19 @@ export class Controller {

this._writeMetadata(test.run);

jmeter.on('close', (code) => {
jmeter.on('close', (code, signal) => {
try {
const duration = endTimer && endTimer({ ...labels, category: run.category, name: run.name });
const updatedTest = { run: { ...run, status: TestRunStatus.done, code: code, duration: duration }, process: jmeter } as Test;
const updatedRun = this._upsertTest(updatedTest).run;
this._writeMetadata(updatedRun);
this._moveToResults(updatedRun.id);
if (!!signal) {
console.info(`[WARN] Ignoring process exit code '${code}' for test ${id} because received signal ${signal}`);
} else {
const duration = endTimer && endTimer({ ...labels, category: run.category, name: run.name });
const updatedTest = { run: { ...run, status: TestRunStatus.done, code: code, duration: duration }, process: jmeter } as Test;
const updatedRun = this._upsertTest(updatedTest).run;
this._writeMetadata(updatedRun);
this._moveToResults(updatedRun.id);
}
} catch (error) {
console.error('Failed to write metadata because: ', error);
console.error('[ERROR] Failed to write metadata because: ', error);
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ server.addHook('onReady', async () => {
try {
await controller.importTestsAndRuns();
} catch (error) {
console.error('Failed to import metadata because: ', error);
console.error('[ERROR] Failed to import metadata because: ', error);
}
});

server.addHook('onClose', async () => {
try {
await controller.exportTestRuns();
} catch (error) {
console.error('Failed to export metadata because: ', error);
console.error('[ERROR] Failed to export metadata because: ', error);
}
})

Expand Down

0 comments on commit 58078cd

Please sign in to comment.