Skip to content

Commit

Permalink
Fix child process (#501)
Browse files Browse the repository at this point in the history
* Revert "remove pstree from dependencies"

This reverts commit 885e87b.

Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com>

* Revert "remove importing pstree"

This reverts commit d305478.

Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com>

* Revert "Clean up iterating to kill child processes"

This reverts commit 9b5cb64.

Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com>

* Revert "kill all child process properly"

This reverts commit ebcff00.

Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com>

* bump up version to 0.0.17

Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com>

* increase timeout for tests

Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com>
  • Loading branch information
NivedhaSenthil committed Nov 2, 2020
1 parent 1a251d7 commit db6199e
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
68 changes: 67 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -8,7 +8,7 @@
"description": "Gauge support for VScode.",
"author": "ThoughtWorks",
"license": "MIT",
"version": "0.0.16",
"version": "0.0.17",
"publisher": "getgauge",
"engines": {
"vscode": "^1.38.0"
Expand Down Expand Up @@ -300,6 +300,7 @@
"clipboardy": "^2.3.0",
"fs-extra": "^9.0.1",
"get-port": "^4.2.0",
"ps-tree": "^1.2.0",
"vscode-jsonrpc": "^5.0.1",
"vscode-languageclient": "^6.1.3",
"vscode-languageserver-protocol": "^3.13.0",
Expand Down
16 changes: 14 additions & 2 deletions src/execution/gaugeExecutor.ts
Expand Up @@ -13,6 +13,7 @@ import { OutputChannel } from './outputChannel';
import { ExecutionConfig } from './executionConfig';
import { CLI } from '../cli';
import { join, relative, extname } from 'path';
import psTree = require('ps-tree');
import {
LineTextProcessor, DebuggerAttachedEventProcessor, DebuggerNotAttachedEventProcessor, ReportEventProcessor
} from './lineProcessors';
Expand Down Expand Up @@ -64,7 +65,7 @@ export class GaugeExecutor extends Disposable {
const relPath = relative(config.getProject().root(), config.getStatus());
this.preExecute.forEach((f) => { f.call(null, env, relPath); });
this.aborted = false;
this.childProcess = spawn(cmd, args, { cwd: config.getProject().root(), env: env, detached: true });
this.childProcess = spawn(cmd, args, { cwd: config.getProject().root(), env: env });
this.childProcess.stdout.on('data', this.filterStdoutDataDumpsToTextLines((lineText: string) => {
chan.appendOutBuf(lineText);
lineText.split("\n").forEach((lineText) => {
Expand Down Expand Up @@ -98,8 +99,19 @@ export class GaugeExecutor extends Disposable {
}
private killRecursive(pid: number, aborted: boolean) {
try {
psTree(pid, (error: Error, children: Array<any>) => {
if (!error && children.length) {
children.forEach((c: any) => {
try {
process.kill(c.PID);
} catch (e) {
if (e.code !== 'ESRCH') throw error;
}
});
}
});
this.aborted = aborted;
return process.kill(-pid);
return process.kill(pid);
} catch (error) {
if (error.code !== 'ESRCH') throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion test/execution/execution.test.ts
Expand Up @@ -64,7 +64,7 @@ suite('Gauge Execution Tests', () => {
setTimeout(() => commands.executeCommand(GaugeVSCodeCommands.StopExecution), 100);
let status = await commands.executeCommand(GaugeVSCodeCommands.Execute, spec);
assertStatus(status, false);
}).timeout(20000);;
});

test('should reject execution when another is already in progress', async () => {
let spec = path.join(testDataPath, 'specs', 'example.spec');
Expand Down

0 comments on commit db6199e

Please sign in to comment.