Skip to content

Break immediately when cancelling a multiple test run #1589

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
May 29, 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: 6 additions & 3 deletions src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export class TestRunner {
private testArgs: TestRunArguments;
private xcTestOutputParser: IXCTestOutputParser;
private swiftTestOutputParser: SwiftTestingOutputParser;
private static CANCELLATION_ERROR = "Test run cancelled";

/**
* Constructor for TestRunner
Expand Down Expand Up @@ -718,8 +719,10 @@ export class TestRunner {
break;
}
} catch (error) {
// Test failures result in error code 1
if (error !== 1) {
if (error === TestRunner.CANCELLATION_ERROR) {
this.testRun.appendOutput(`\r\n${error}`);
} else if (error !== 1) {
// Test failures result in error code 1
this.testRun.appendOutput(`\r\nError: ${getErrorDescription(error)}`);
} else {
// swift-testing tests don't have their run started until the .swift-testing binary has
Expand Down Expand Up @@ -793,7 +796,7 @@ export class TestRunner {
// 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");
reject("Test run cancelled");
reject(TestRunner.CANCELLATION_ERROR);
});

task.execution.onDidClose(code => {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/testMultipleTimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export async function runTestMultipleTimes(

runStates.push(runState);

if (untilFailure && (runState.failed.length > 0 || runState.errored.length > 0)) {
if (
runner.testRun.isCancellationRequested ||
(untilFailure && (runState.failed.length > 0 || runState.errored.length > 0))
) {
break;
}
}
Expand Down