From 31f809acca92ff89bd0ce8617192ba30bc3b28d1 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 13 Sep 2022 16:55:30 +0800 Subject: [PATCH] test: ignore stale process cleanup failures on Windows In some tests we try to clean up stale child processes on Windows, but they don't necessarily exist, in that case we should ignore any failures from the WMIC.exe command. PR-URL: https://github.com/nodejs/node/pull/44480 Reviewed-By: Luigi Pinca --- test/common/child_process.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/common/child_process.js b/test/common/child_process.js index 30669821bf4165..6d52e33fcef8d4 100644 --- a/test/common/child_process.js +++ b/test/common/child_process.js @@ -12,14 +12,18 @@ function cleanupStaleProcess(filename) { } process.once('beforeExit', () => { const basename = filename.replace(/.*[/\\]/g, ''); - require('child_process') - .execFileSync(`${process.env.SystemRoot}\\System32\\wbem\\WMIC.exe`, [ - 'process', - 'where', - `commandline like '%${basename}%child'`, - 'delete', - '/nointeractive', - ]); + try { + require('child_process') + .execFileSync(`${process.env.SystemRoot}\\System32\\wbem\\WMIC.exe`, [ + 'process', + 'where', + `commandline like '%${basename}%child'`, + 'delete', + '/nointeractive', + ]); + } catch { + // Ignore failures, there might not be any stale process to clean up. + } }); }