Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/automation/src/processes.ts')
-rw-r--r--test/automation/src/processes.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/automation/src/processes.ts b/test/automation/src/processes.ts
new file mode 100644
index 00000000000..17dcb79b32b
--- /dev/null
+++ b/test/automation/src/processes.ts
@@ -0,0 +1,34 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+import { ChildProcess } from 'child_process';
+import { promisify } from 'util';
+import * as treekill from 'tree-kill';
+import { Logger } from './logger';
+
+export async function teardown(p: ChildProcess, logger: Logger, retryCount = 3): Promise<void> {
+ const pid = p.pid;
+ if (typeof pid !== 'number') {
+ return;
+ }
+
+ let retries = 0;
+ while (retries < retryCount) {
+ retries++;
+
+ try {
+ return await promisify(treekill)(pid);
+ } catch (error) {
+ try {
+ process.kill(pid, 0); // throws an exception if the process doesn't exist anymore
+ logger.log(`Error tearing down process (pid: ${pid}, attempt: ${retries}): ${error}`);
+ } catch (error) {
+ return; // Expected when process is gone
+ }
+ }
+ }
+
+ logger.log(`Gave up tearing down process client after ${retries} attempts...`);
+}