From 84f102091bc86a149680664627a343e68689e185 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Wed, 21 Aug 2024 16:01:03 +0200 Subject: [PATCH] spawn kill --- apps/remix-ide-e2e/src/tests/remixd.test.ts | 41 ++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/remixd.test.ts b/apps/remix-ide-e2e/src/tests/remixd.test.ts index a234c6a4b6..5b07e5bfa9 100644 --- a/apps/remix-ide-e2e/src/tests/remixd.test.ts +++ b/apps/remix-ide-e2e/src/tests/remixd.test.ts @@ -55,15 +55,25 @@ module.exports = { before: function (browser, done) { init(browser, done) }, - afterEach: function (browser, done) { - console.log('afterEach') - done() + afterEach: async function (browser, done) { + if (browser.currentTest.results.failed > 0) { + // Perform actions if the test case failed + console.log('Test failed, disconnecting services...'); + console.log('remixd', remixd.pid) + } + done(); }, after: function (browser) { - browser.perform((done) => { + console.log('after') + browser.perform(async (done) => { console.log('remixd', remixd.pid) - kill(remixd.pid) + try { + await killProcess(remixd.pid) + }catch(e){ + + } done() + browser.end() }) }, @@ -402,6 +412,27 @@ async function spawnRemixd(path: string): Promise { }) } +function killProcess(pid, signal = 'SIGKILL') { + return new Promise((resolve, reject) => { + const kill = spawn('kill', ['-s', signal, pid]); + + kill.on('close', (code) => { + if (code === 0) { + console.log(`Successfully killed process with PID: ${pid}`); + resolve(); + } else { + console.error(`Failed to kill process with PID: ${pid}. Exit code: ${code}`); + reject(new Error(`kill process failed with code ${code}`)); + } + }); + + kill.on('error', (err) => { + console.error(`Error spawning kill process: ${err.message}`); + reject(err); + }); + }); +} + function connectRemixd(browser: NightwatchBrowser, done: any) { const browserName = browser.options.desiredCapabilities.browserName if (browserName === 'safari' || browserName === 'internet explorer') {