diff --git a/src/client/testing/common/debugLauncher.ts b/src/client/testing/common/debugLauncher.ts index b0f318905c78..f7a027ad1304 100644 --- a/src/client/testing/common/debugLauncher.ts +++ b/src/client/testing/common/debugLauncher.ts @@ -31,7 +31,7 @@ export class DebugLauncher implements ITestDebugLauncher { this.configService = this.serviceContainer.get(IConfigurationService); } - public async launchDebugger(options: LaunchOptions): Promise { + public async launchDebugger(options: LaunchOptions, callback?: () => void): Promise { if (options.token && options.token.isCancellationRequested) { return undefined; } @@ -47,6 +47,7 @@ export class DebugLauncher implements ITestDebugLauncher { const deferred = createDeferred(); debugManager.onDidTerminateDebugSession(() => { deferred.resolve(); + callback?.(); }); debugManager.startDebugging(workspaceFolder, launchArgs); return deferred.promise; diff --git a/src/client/testing/common/types.ts b/src/client/testing/common/types.ts index 7104260abfcf..29a6de7768cb 100644 --- a/src/client/testing/common/types.ts +++ b/src/client/testing/common/types.ts @@ -88,7 +88,7 @@ export interface ITestConfigurationManagerFactory { } export const ITestDebugLauncher = Symbol('ITestDebugLauncher'); export interface ITestDebugLauncher { - launchDebugger(options: LaunchOptions): Promise; + launchDebugger(options: LaunchOptions, callback?: () => void): Promise; } export const IUnitTestSocketServer = Symbol('IUnitTestSocketServer'); diff --git a/src/client/testing/testController/common/server.ts b/src/client/testing/testController/common/server.ts index 7813e2a568b2..6bd9bf348e20 100644 --- a/src/client/testing/testController/common/server.ts +++ b/src/client/testing/testController/common/server.ts @@ -106,7 +106,7 @@ export class PythonTestServer implements ITestServer, Disposable { return this._onDataReceived.event; } - async sendCommand(options: TestCommandOptions, runTestIdPort?: string): Promise { + async sendCommand(options: TestCommandOptions, runTestIdPort?: string, callback?: () => void): Promise { const { uuid } = options; const spawnOptions: SpawnOptions = { token: options.token, @@ -146,7 +146,10 @@ export class PythonTestServer implements ITestServer, Disposable { runTestIdsPort: runTestIdPort, }; traceInfo(`Running DEBUG unittest with arguments: ${args}\r\n`); - await this.debugLauncher!.launchDebugger(launchOptions); + + await this.debugLauncher!.launchDebugger(launchOptions, () => { + callback?.(); + }); } else { if (isRun) { // This means it is running the test diff --git a/src/client/testing/testController/common/types.ts b/src/client/testing/testController/common/types.ts index e3dd37d0d984..4307d7a3913f 100644 --- a/src/client/testing/testController/common/types.ts +++ b/src/client/testing/testController/common/types.ts @@ -172,7 +172,7 @@ export type TestCommandOptionsPytest = { */ export interface ITestServer { readonly onDataReceived: Event; - sendCommand(options: TestCommandOptions, runTestIdsPort?: string): Promise; + sendCommand(options: TestCommandOptions, runTestIdsPort?: string, callback?: () => void): Promise; serverReady(): Promise; getPort(): number; createUUID(cwd: string): string; diff --git a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts index a6a9963cbf75..90704b5d67f4 100644 --- a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts +++ b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts @@ -171,17 +171,16 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { runTestIdsPort: pytestRunTestIdsPort, }; traceInfo(`Running DEBUG pytest with arguments: ${testArgs.join(' ')}\r\n`); - await debugLauncher!.launchDebugger(launchOptions); + await debugLauncher!.launchDebugger(launchOptions, () => { + deferred.resolve(); + }); } else { // combine path to run script with run args const scriptPath = path.join(fullPluginPath, 'vscode_pytest', 'run_pytest_script.py'); const runArgs = [scriptPath, ...testArgs]; traceInfo(`Running pytests with arguments: ${runArgs.join(' ')}\r\n`); - await execService?.exec(runArgs, spawnOptions).catch((ex) => { - traceError(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`); - return Promise.reject(ex); - }); + await execService?.exec(runArgs, spawnOptions); } } catch (ex) { traceError(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`); diff --git a/src/client/testing/testController/unittest/testExecutionAdapter.ts b/src/client/testing/testController/unittest/testExecutionAdapter.ts index abe386171a0e..bf83c3c0feb1 100644 --- a/src/client/testing/testController/unittest/testExecutionAdapter.ts +++ b/src/client/testing/testController/unittest/testExecutionAdapter.ts @@ -99,7 +99,9 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { runTestIdsPort = assignedPort.toString(); // Send test command to server. // Server fire onDataReceived event once it gets response. - this.testServer.sendCommand(options, runTestIdsPort); // does this need an await? + this.testServer.sendCommand(options, runTestIdsPort, () => { + deferred.resolve(); + }); }) .catch((error) => { traceError('Error starting server:', error);