From c261fd8507cf4a21cb3333ce5f2013044264cafe Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Tue, 27 Jun 2023 11:31:11 -0700 Subject: [PATCH] E2E: Manually kill processes in the same group This only applies to Linux & darwin. Signed-off-by: Mark Yen --- e2e/utils/TestUtils.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/e2e/utils/TestUtils.ts b/e2e/utils/TestUtils.ts index d8bfafe70ec..303f2a91855 100644 --- a/e2e/utils/TestUtils.ts +++ b/e2e/utils/TestUtils.ts @@ -157,6 +157,31 @@ export async function teardown(app: ElectronApplication, filename: string) { if (proc.kill('SIGTERM') || proc.kill('SIGKILL')) { console.log(`Manually stopped process ${ pid }`); } + // Try to do platform-specific killing based on process groups + if (process.platform === 'darwin' || process.platform === 'linux') { + for (const signal of ['TERM', 'TERM', 'TERM', 'KILL']) { + let pids = ''; + + try { + const args = ['-o', 'pid=', process.platform === 'darwin' ? '-g' : '--sid', `${ pid }`]; + + pids = (await childProcess.spawnFile('ps', args, { stdio: ['ignore', 'pipe', 'inherit'] })).stdout; + } catch (ex) { + console.log(`Did not find processes in process group, ignoring.`); + break; + } + + try { + if (pids.trim()) { + console.log(`Manually killing group processes ${ pids.replace(/\r?\n/g, ' ').trim() }`); + await childProcess.spawnFile('kill', ['-s', signal].concat(...pids.split(/\s+/).filter(p => p))); + } + } catch (ex) { + console.log(`Failed to process group: ${ ex } (retrying)`); + } + await util.promisify(setTimeout)(1_000); + } + } } if (testInfo?.testPath === filename) {