Skip to content

Commit 93e95c8

Browse files
committed
Fix flaky test
I believe this test was flaky due to race conditions caused by the events. Awaiting promises instead should eliminate those races.
1 parent d367a8d commit 93e95c8

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

test/features/DebugSession.test.ts

+17-21
Original file line numberDiff line numberDiff line change
@@ -440,31 +440,27 @@ describe("DebugSessionFeature E2E", function slowTests() {
440440

441441
it("Starts and stops a debugging session", async () => {
442442
// Inspect the debug session via the started events to ensure it is correct
443-
let startDebugSession: DebugSession;
444-
let stopDebugSession: DebugSession;
445-
const interactiveSessionConfig = defaultDebugConfigurations[DebugConfig.InteractiveSession];
446-
// Asserts don't seem to fire in this event or the event doesn't resolve
447-
// in the test code flow, so we need to "extract" the values for later
448-
// use by the asserts
449-
450-
const startDebugEvent = debug.onDidStartDebugSession((newDebugSession) => {
451-
startDebugEvent.dispose();
452-
startDebugSession = newDebugSession;
453-
const stopDebugEvent = debug.onDidTerminateDebugSession((terminatedDebugSession) => {
454-
stopDebugEvent.dispose();
455-
stopDebugSession = terminatedDebugSession;
443+
const startDebugSession = new Promise<DebugSession>((resolve) => {
444+
const event = debug.onDidStartDebugSession((session) => {
445+
resolve(session);
446+
event.dispose();
447+
});
448+
});
449+
const stopDebugSession = new Promise<DebugSession>((resolve) => {
450+
const event = debug.onDidTerminateDebugSession((session) => {
451+
resolve(session);
452+
event.dispose();
456453
});
457454
});
458455

459-
const debugSessionStarted = await debug.startDebugging(undefined, interactiveSessionConfig);
460-
assert.ok(debugSessionStarted, "Debug session should start");
461-
assert.equal(startDebugSession!.name, interactiveSessionConfig.name, "Debug session name should match when started");
462-
// debugSession var should be populated from the event before startDebugging completes
463-
await debug.stopDebugging(startDebugSession!);
456+
const config = defaultDebugConfigurations[DebugConfig.InteractiveSession];
457+
assert.ok(await debug.startDebugging(undefined, config), "Debug session should start");
458+
assert.equal((await startDebugSession).name, config.name, "Debug session name should match when started");
464459

465-
assert.equal(stopDebugSession!.name, interactiveSessionConfig.name, "Debug session name should match when stopped");
466-
assert.equal(stopDebugSession!.configuration.internalConsoleOptions, "neverOpen", "Debug session should always have neverOpen internalConsoleOptions");
467-
assert.ok(stopDebugSession!, "Debug session should stop");
460+
await debug.stopDebugging(await startDebugSession);
461+
assert.ok(await stopDebugSession, "Debug session should stop");
462+
assert.equal((await stopDebugSession).name, config.name, "Debug session name should match when stopped");
463+
assert.equal((await stopDebugSession).configuration.internalConsoleOptions, "neverOpen", "Debug session should always have neverOpen internalConsoleOptions");
468464
});
469465

470466
describe("Binary Modules", () => {

0 commit comments

Comments
 (0)