Skip to content

Terminate process under test on test run cancellation #1391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,14 @@ export class TestRunner {
outputStream.write(replaced);
});

// If the test run is iterrupted by a cancellation request from VS Code, ensure the task is terminated.
const cancellationDisposable = this.testRun.token.onCancellationRequested(() => {
task.execution.terminate("SIGINT");
});

task.execution.onDidClose(code => {
cancellationDisposable.dispose();

// undefined or 0 are viewed as success
if (!code) {
resolve();
Expand Down Expand Up @@ -925,7 +932,6 @@ export class TestRunner {
return;
}

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

// add cancellation
const cancellation = this.testRun.token.onCancellationRequested(() => {
this.workspaceContext.outputChannel.logDiagnostic(
"Test Debugging Cancelled",
Expand Down
9 changes: 8 additions & 1 deletion src/tasks/SwiftExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SwiftExecution extends vscode.CustomExecution {
public readonly command: string,
public readonly args: string[],
public readonly options: SwiftExecutionOptions,
swiftProcess: SwiftProcess = new SwiftPtyProcess(command, args, options)
private readonly swiftProcess: SwiftProcess = new SwiftPtyProcess(command, args, options)
) {
super(async () => {
return new SwiftPseudoterminal(swiftProcess, options.presentation || {});
Expand All @@ -54,4 +54,11 @@ export class SwiftExecution extends vscode.CustomExecution {
* @see {@link SwiftProcess.onDidClose}
*/
onDidClose: vscode.Event<number | void>;

/**
* Terminate the underlying executable.
*/
terminate(signal?: NodeJS.Signals) {
this.swiftProcess.terminate(signal);
}
}