Skip to content

Commit 2c43d6f

Browse files
authored
Terminate process under test on test run cancellation (#1391)
During a standard test run (not using the debugger) a cancellation request from VS Code did not terminate the process under test, which lead to it being orphaned. Issue: #1389
1 parent 0296cbe commit 2c43d6f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/TestExplorer/TestRunner.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,14 @@ export class TestRunner {
729729
outputStream.write(replaced);
730730
});
731731

732+
// If the test run is iterrupted by a cancellation request from VS Code, ensure the task is terminated.
733+
const cancellationDisposable = this.testRun.token.onCancellationRequested(() => {
734+
task.execution.terminate("SIGINT");
735+
});
736+
732737
task.execution.onDidClose(code => {
738+
cancellationDisposable.dispose();
739+
733740
// undefined or 0 are viewed as success
734741
if (!code) {
735742
resolve();
@@ -925,7 +932,6 @@ export class TestRunner {
925932
return;
926933
}
927934

928-
// add cancelation
929935
const startSession = vscode.debug.onDidStartDebugSession(session => {
930936
if (config.testType === TestLibrary.xctest) {
931937
this.testRun.testRunStarted();
@@ -945,6 +951,7 @@ export class TestRunner {
945951
}
946952
);
947953

954+
// add cancellation
948955
const cancellation = this.testRun.token.onCancellationRequested(() => {
949956
this.workspaceContext.outputChannel.logDiagnostic(
950957
"Test Debugging Cancelled",

src/tasks/SwiftExecution.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class SwiftExecution extends vscode.CustomExecution {
3030
public readonly command: string,
3131
public readonly args: string[],
3232
public readonly options: SwiftExecutionOptions,
33-
swiftProcess: SwiftProcess = new SwiftPtyProcess(command, args, options)
33+
private readonly swiftProcess: SwiftProcess = new SwiftPtyProcess(command, args, options)
3434
) {
3535
super(async () => {
3636
return new SwiftPseudoterminal(swiftProcess, options.presentation || {});
@@ -54,4 +54,11 @@ export class SwiftExecution extends vscode.CustomExecution {
5454
* @see {@link SwiftProcess.onDidClose}
5555
*/
5656
onDidClose: vscode.Event<number | void>;
57+
58+
/**
59+
* Terminate the underlying executable.
60+
*/
61+
terminate(signal?: NodeJS.Signals) {
62+
this.swiftProcess.terminate(signal);
63+
}
5764
}

0 commit comments

Comments
 (0)