Skip to content

Commit a395e2e

Browse files
authored
fix bug so canceling debug works in rewrite (#21361)
fixes #21336
1 parent be829b3 commit a395e2e

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

src/client/testing/common/debugLauncher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class DebugLauncher implements ITestDebugLauncher {
3131
this.configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
3232
}
3333

34-
public async launchDebugger(options: LaunchOptions): Promise<void> {
34+
public async launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void> {
3535
if (options.token && options.token.isCancellationRequested) {
3636
return undefined;
3737
}
@@ -47,6 +47,7 @@ export class DebugLauncher implements ITestDebugLauncher {
4747
const deferred = createDeferred<void>();
4848
debugManager.onDidTerminateDebugSession(() => {
4949
deferred.resolve();
50+
callback?.();
5051
});
5152
debugManager.startDebugging(workspaceFolder, launchArgs);
5253
return deferred.promise;

src/client/testing/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface ITestConfigurationManagerFactory {
8888
}
8989
export const ITestDebugLauncher = Symbol('ITestDebugLauncher');
9090
export interface ITestDebugLauncher {
91-
launchDebugger(options: LaunchOptions): Promise<void>;
91+
launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void>;
9292
}
9393

9494
export const IUnitTestSocketServer = Symbol('IUnitTestSocketServer');

src/client/testing/testController/common/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class PythonTestServer implements ITestServer, Disposable {
106106
return this._onDataReceived.event;
107107
}
108108

109-
async sendCommand(options: TestCommandOptions, runTestIdPort?: string): Promise<void> {
109+
async sendCommand(options: TestCommandOptions, runTestIdPort?: string, callback?: () => void): Promise<void> {
110110
const { uuid } = options;
111111
const spawnOptions: SpawnOptions = {
112112
token: options.token,
@@ -146,7 +146,10 @@ export class PythonTestServer implements ITestServer, Disposable {
146146
runTestIdsPort: runTestIdPort,
147147
};
148148
traceInfo(`Running DEBUG unittest with arguments: ${args}\r\n`);
149-
await this.debugLauncher!.launchDebugger(launchOptions);
149+
150+
await this.debugLauncher!.launchDebugger(launchOptions, () => {
151+
callback?.();
152+
});
150153
} else {
151154
if (isRun) {
152155
// This means it is running the test

src/client/testing/testController/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export type TestCommandOptionsPytest = {
172172
*/
173173
export interface ITestServer {
174174
readonly onDataReceived: Event<DataReceivedEvent>;
175-
sendCommand(options: TestCommandOptions, runTestIdsPort?: string): Promise<void>;
175+
sendCommand(options: TestCommandOptions, runTestIdsPort?: string, callback?: () => void): Promise<void>;
176176
serverReady(): Promise<void>;
177177
getPort(): number;
178178
createUUID(cwd: string): string;

src/client/testing/testController/pytest/pytestExecutionAdapter.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,16 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
171171
runTestIdsPort: pytestRunTestIdsPort,
172172
};
173173
traceInfo(`Running DEBUG pytest with arguments: ${testArgs.join(' ')}\r\n`);
174-
await debugLauncher!.launchDebugger(launchOptions);
174+
await debugLauncher!.launchDebugger(launchOptions, () => {
175+
deferred.resolve();
176+
});
175177
} else {
176178
// combine path to run script with run args
177179
const scriptPath = path.join(fullPluginPath, 'vscode_pytest', 'run_pytest_script.py');
178180
const runArgs = [scriptPath, ...testArgs];
179181
traceInfo(`Running pytests with arguments: ${runArgs.join(' ')}\r\n`);
180182

181-
await execService?.exec(runArgs, spawnOptions).catch((ex) => {
182-
traceError(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`);
183-
return Promise.reject(ex);
184-
});
183+
await execService?.exec(runArgs, spawnOptions);
185184
}
186185
} catch (ex) {
187186
traceError(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`);

src/client/testing/testController/unittest/testExecutionAdapter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
9999
runTestIdsPort = assignedPort.toString();
100100
// Send test command to server.
101101
// Server fire onDataReceived event once it gets response.
102-
this.testServer.sendCommand(options, runTestIdsPort); // does this need an await?
102+
this.testServer.sendCommand(options, runTestIdsPort, () => {
103+
deferred.resolve();
104+
});
103105
})
104106
.catch((error) => {
105107
traceError('Error starting server:', error);

0 commit comments

Comments
 (0)