From 10e8f637034713c564d27fcdab4ae5f78e2aec28 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Thu, 28 Sep 2023 09:03:59 +0000 Subject: [PATCH] Bug 1772329 - Force kill node process and subprocesses in xpcshell tests at the end of the test r=jmaher,necko-reviewers,kershaw Differential Revision: https://phabricator.services.mozilla.com/D189212 --- netwerk/test/unit/test_node_execute.js | 8 ++++++++ testing/xpcshell/runxpcshelltests.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/netwerk/test/unit/test_node_execute.js b/netwerk/test/unit/test_node_execute.js index 3640514a8e7e..bf0fcbbfe132 100644 --- a/netwerk/test/unit/test_node_execute.js +++ b/netwerk/test/unit/test_node_execute.js @@ -85,3 +85,11 @@ add_task(async function test_execute() { ) ); }); + +add_task(async function killOnEnd() { + let id = await NodeServer.fork(); + // Make the forked subprocess hang forever. + NodeServer.execute(id, "while (true) {}").catch(e => {}); + await new Promise(resolve => do_timeout(10, resolve)); + // Should get killed at the end of the test by the harness. +}); diff --git a/testing/xpcshell/runxpcshelltests.py b/testing/xpcshell/runxpcshelltests.py index 100b1bfd18b9..53e7afdfd443 100755 --- a/testing/xpcshell/runxpcshelltests.py +++ b/testing/xpcshell/runxpcshelltests.py @@ -1434,6 +1434,9 @@ class XPCShellTests(object): self.log.info("Node %s server shutting down ..." % name) if proc.poll() is not None: self.log.info("Node server %s already dead %s" % (name, proc.poll())) + elif sys.platform != "win32": + # Kill process and all its spawned children. + os.killpg(os.getpgid(proc.pid), signal.SIGTERM) else: proc.terminate()