Skip to content

Commit

Permalink
TINY-11177: Attempt to properly cancel when ctrl+c is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpyder committed Jan 14, 2025
1 parent 6b0857d commit 9e5effe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/server/src/main/ts/BedrockAuto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export const go = (bedrockAutoSettings: BedrockAutoSettings): void => {
});
shutdownServices.push(service.shutdown, driver.shutdown);

const cancelEverything = Lifecycle.cancel(webdriver, shutdown(shutdownServices), settings.gruntDone);
process.on('SIGINT', cancelEverything);
process.on('SIGQUIT', cancelEverything);
process.on('SIGTERM', cancelEverything);

try {
if (!isHeadless) {
console.log('bedrock-auto ' + Version.get() + ' available at: ' + location);
Expand Down
13 changes: 13 additions & 0 deletions modules/server/src/main/ts/bedrock/core/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ export const error = async (err: Error | string, driver: Browser, shutdown: Shut
await shutdown(true);
exit(gruntDone, ExitCodes.failures.unexpected);
};

export const cancel = (driver: Browser, shutdown: ShutdownFn, gruntDone: GruntDoneFn): () => Promise<void> => {
let cancelled = false;
return async () => {
if (cancelled) {
return;
}
cancelled = true;
console.error(chalk.red('********** Cancelling test run **********'));
await shutdown(true);
exit(gruntDone, ExitCodes.failures.unexpected);
};
};

0 comments on commit 9e5effe

Please sign in to comment.