Skip to content

Commit 4852aff

Browse files
authored
Break immediately when cancelling a multiple test run (#1589)
When using "Run Test Multiple Times" or "Run Until Failure" cancelling the run would prevent subsequent test runs from occuring, but the logs would still print out "Beginning Test Iteration #x" for each remaining test iteration. Exit out of the loop that is running the tests multiple times once cancellation has been requested. Also clean up the cancellation error message in the logs to be formatted not as an error but just a message.
1 parent ea46358 commit 4852aff

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/TestExplorer/TestRunner.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ export class TestRunner {
374374
private testArgs: TestRunArguments;
375375
private xcTestOutputParser: IXCTestOutputParser;
376376
private swiftTestOutputParser: SwiftTestingOutputParser;
377+
private static CANCELLATION_ERROR = "Test run cancelled";
377378

378379
/**
379380
* Constructor for TestRunner
@@ -718,8 +719,10 @@ export class TestRunner {
718719
break;
719720
}
720721
} catch (error) {
721-
// Test failures result in error code 1
722-
if (error !== 1) {
722+
if (error === TestRunner.CANCELLATION_ERROR) {
723+
this.testRun.appendOutput(`\r\n${error}`);
724+
} else if (error !== 1) {
725+
// Test failures result in error code 1
723726
this.testRun.appendOutput(`\r\nError: ${getErrorDescription(error)}`);
724727
} else {
725728
// swift-testing tests don't have their run started until the .swift-testing binary has
@@ -793,7 +796,7 @@ export class TestRunner {
793796
// If the test run is iterrupted by a cancellation request from VS Code, ensure the task is terminated.
794797
const cancellationDisposable = this.testRun.token.onCancellationRequested(() => {
795798
task.execution.terminate("SIGINT");
796-
reject("Test run cancelled");
799+
reject(TestRunner.CANCELLATION_ERROR);
797800
});
798801

799802
task.execution.onDidClose(code => {

src/commands/testMultipleTimes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ export async function runTestMultipleTimes(
7575

7676
runStates.push(runState);
7777

78-
if (untilFailure && (runState.failed.length > 0 || runState.errored.length > 0)) {
78+
if (
79+
runner.testRun.isCancellationRequested ||
80+
(untilFailure && (runState.failed.length > 0 || runState.errored.length > 0))
81+
) {
7982
break;
8083
}
8184
}

0 commit comments

Comments
 (0)