From 788f9f953a996b36c0b3c221554342bc6abdaa0f Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Fri, 6 Oct 2023 14:17:17 +0300 Subject: [PATCH 1/2] Remove unneeded delay befor test --- lib/application.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/application.js b/lib/application.js index 6b1dc482..51227f1a 100644 --- a/lib/application.js +++ b/lib/application.js @@ -134,21 +134,20 @@ class Application extends EventEmitter { } const { concurrency, size, timeout } = config.server.queue; this.semaphore = new Semaphore(concurrency, size, timeout); - if (mode === 'test' && threadId === 1) this.test(); this.initialization = false; sandbox.application.emit('started'); + if (mode === 'test' && threadId === 1) this.test(); } - async test() { - setTimeout(async () => { - await this.parallel( - this.tests.map((test) => - node.test(test.name, (t) => this.execute(test.run, t)), - ), - ERR_TEST, - ); + test() { + this.parallel( + this.tests.map((test) => + node.test(test.name, (t) => this.execute(test.run, t)), + ), + ERR_TEST, + ).then(() => { process.kill(process.pid, 'SIGINT'); - }, 1000); + }); } async shutdown() { From d715fabe3771d25ef1550c3856ee656d285ae63f Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Fri, 6 Oct 2023 17:53:27 +0300 Subject: [PATCH 2/2] Use common shutdown to stop process after tests --- impress.js | 5 +++++ lib/application.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/impress.js b/impress.js index 039ade3e..cc46373b 100644 --- a/impress.js +++ b/impress.js @@ -102,6 +102,10 @@ const startWorker = async (app, kind, port, id = ++impress.lastWorkerId) => { if (!next) return; next.postMessage(msg, [port]); }, + + terminate: () => { + process.emit('TERMINATE'); + }, }; worker.on('message', (msg) => { @@ -204,6 +208,7 @@ process.on('uncaughtException', logError('Uncaught exception')); process.on('unhandledRejection', logError('Unhandled rejection')); process.on('SIGINT', stop); process.on('SIGTERM', stop); +process.on('TERMINATE', stop); if (process.stdin.isTTY) { process.stdin.setRawMode(true); diff --git a/lib/application.js b/lib/application.js index 51227f1a..b879a8fc 100644 --- a/lib/application.js +++ b/lib/application.js @@ -146,7 +146,7 @@ class Application extends EventEmitter { ), ERR_TEST, ).then(() => { - process.kill(process.pid, 'SIGINT'); + wt.parentPort.postMessage({ name: 'terminate' }); }); }