From 249486490e02d58327554e60f314f091f55b2554 Mon Sep 17 00:00:00 2001 From: Mate Pek Date: Thu, 14 Mar 2019 21:18:34 +0100 Subject: [PATCH] fixed a bug related to debugging --- CHANGELOG.md | 6 ++++ src/TestAdapter.ts | 39 +++++++++++++++--------- src/test/TestCatch2FrameworkLoad.test.ts | 2 +- src/test/TestExecutablesVariable.test.ts | 4 ++- src/test/TestLogOutputContent.test.ts | 2 +- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e17aaf0f..28d85c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.3.24] + +### Fixed + +- a bug related to debugging (https://github.com/Microsoft/vscode/issues/70125). + ### Changed - test suite loading order from now is not deterministic. One can set `testExplorer.sort` for ordering. diff --git a/src/TestAdapter.ts b/src/TestAdapter.ts index df9a0a53..77c6ab0f 100644 --- a/src/TestAdapter.ts +++ b/src/TestAdapter.ts @@ -18,7 +18,7 @@ import * as api from 'vscode-test-adapter-api'; import * as util from 'vscode-test-adapter-util'; import { RootTestSuiteInfo } from './RootTestSuiteInfo'; -import { resolveVariables } from './Util'; +import { resolveVariables, generateUniqueId } from './Util'; import { TaskQueue } from './TaskQueue'; import { TestExecutableInfo } from './TestExecutableInfo'; import { SharedVariables } from './SharedVariables'; @@ -387,32 +387,41 @@ export class TestAdapter implements api.TestAdapter, vscode.Disposable { ['${envObj}', Object.assign(Object.assign({}, process.env), testSuite.execOptions.env!)], ]); + // we dont know better :( + // https://github.com/Microsoft/vscode/issues/70125 + const magicValueKey = 'magic variable 🤦🏼‍♂️'; + const magicValue = generateUniqueId(); + debugConfig[magicValueKey] = magicValue; + this._log.info('Debug: resolved catch2TestExplorer.debugConfigTemplate:', debugConfig); + const terminated = new Promise(resolve => { + const conn = vscode.debug.onDidTerminateDebugSession((session: vscode.DebugSession) => { + const session2 = (session as unknown) as { configuration: { [prop: string]: string } }; + if (session2.configuration && session2.configuration[magicValueKey] === magicValue) { + resolve(session); + conn.dispose(); + } + }); + }); + return this._mainTaskQueue.then(() => { return vscode.debug .startDebugging(this.workspaceFolder, debugConfig) .then((debugSessionStarted: boolean) => { - const currentSession = vscode.debug.activeDebugSession; - - if (!debugSessionStarted || !currentSession) { + if (!debugSessionStarted) { return Promise.reject( - 'Failed starting the debug session - aborting. Maybe something wrong with "catch2TestExplorer.debugConfigTemplate"; ' + - +debugSessionStarted + - '; ' + - currentSession, + new Error( + 'Failed starting the debug session. ' + + 'Maybe something wrong with "catch2TestExplorer.debugConfigTemplate".', + ), ); } this._log.info('debugSessionStarted'); - return new Promise(resolve => { - const subscription = vscode.debug.onDidTerminateDebugSession(session => { - if (currentSession != session) return; - this._log.info('Debug session ended.'); - resolve(); - subscription.dispose(); - }); + return terminated.finally(() => { + this._log.info('debugSessionTerminated'); }); }) .then(undefined, (reason: Error) => { diff --git a/src/test/TestCatch2FrameworkLoad.test.ts b/src/test/TestCatch2FrameworkLoad.test.ts index 0af5ce4b..79372219 100644 --- a/src/test/TestCatch2FrameworkLoad.test.ts +++ b/src/test/TestCatch2FrameworkLoad.test.ts @@ -1432,7 +1432,7 @@ describe(path.basename(__filename), function() { await adapter.load(); - startDebuggingStub.onFirstCall().resolves(true); + startDebuggingStub.onFirstCall().resolves(false); try { await adapter.debug([adapter.suite1.children[0].id]); diff --git a/src/test/TestExecutablesVariable.test.ts b/src/test/TestExecutablesVariable.test.ts index 2f64d12a..7f22f7a3 100644 --- a/src/test/TestExecutablesVariable.test.ts +++ b/src/test/TestExecutablesVariable.test.ts @@ -15,8 +15,10 @@ describe(path.basename(__filename), function() { let adapter: TestAdapter; before(async function() { - await settings.resetConfig(); + this.timeout(4000); + imitation = new Imitation(); + await settings.resetConfig(); }); beforeEach(function() { diff --git a/src/test/TestLogOutputContent.test.ts b/src/test/TestLogOutputContent.test.ts index 16cce291..ef8e0543 100644 --- a/src/test/TestLogOutputContent.test.ts +++ b/src/test/TestLogOutputContent.test.ts @@ -28,7 +28,7 @@ const expectedErrorLines = new Map>([ [ 'TestCatch2FrameworkLoad.test.js -> vscode.debug -> should be debugged', new Set([ - '[ERROR] Failed starting the debug session - aborting. Maybe something wrong with "catch2TestExplorer.debugConfigTemplate"; 1; undefined', + '[ERROR] Error: Failed starting the debug session. Maybe something wrong with "catch2TestExplorer.debugConfigTemplate".', ]), ], ]);