Skip to content

Commit 012985c

Browse files
authored
Fix debug test failure (#739)
* 🐛 fix stack frame test (separate the tests)
1 parent fc5171c commit 012985c

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

src/test/debugger/misc.test.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ suite('Standard Debugging - Misc tests', () => {
354354
await debugClient.assertStoppedLocation('exception', pauseLocation);
355355
});
356356
test('Test multi-threaded debugging', async () => {
357-
const threadIdPromise = debugClient.waitForEvent('thread');
358-
359357
await Promise.all([
360358
debugClient.configurationSequence(),
361359
debugClient.launch(buildLauncArgs('multiThread.py', false)),
@@ -370,31 +368,37 @@ suite('Standard Debugging - Misc tests', () => {
370368
});
371369

372370
// hit breakpoint.
373-
const threadId = ((await threadIdPromise) as ThreadEvent).body.threadId;
374-
const stackFramesPromise = debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
375-
await debugClient.continueRequest({ threadId });
376-
await stackFramesPromise;
371+
await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
377372

378373
const threads = await debugClient.threadsRequest();
379374
expect(threads.body.threads).of.lengthOf(2, 'incorrect number of threads');
375+
});
376+
test('Test stack frames', async () => {
377+
await Promise.all([
378+
debugClient.configurationSequence(),
379+
debugClient.launch(buildLauncArgs('stackFrame.py', false)),
380+
debugClient.waitForEvent('initialized')
381+
]);
382+
const pythonFile = path.join(debugFilesPath, 'stackFrame.py');
383+
const breakpointLocation = { path: pythonFile, column: 0, line: 5 };
384+
await debugClient.setBreakpointsRequest({
385+
lines: [breakpointLocation.line],
386+
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
387+
source: { path: breakpointLocation.path }
388+
});
380389

381-
for (const thread of threads.body.threads) {
382-
const stackframes = await debugClient.stackTraceRequest({ threadId: thread.id });
383-
if (thread.name === 'MainThread') {
384-
expect(stackframes.body.stackFrames[0].line).to.be.equal(11, 'incorrect line number for main thread stack');
385-
expect(stackframes.body.stackFrames[0].source!.path).to.be.equal(pythonFile, 'incorrect source file for main thread stack');
390+
// hit breakpoint.
391+
const stackframes = await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
386392

387-
expect(stackframes.body.stackFrames[1].line).to.be.equal(14, 'incorrect line number for main thread stack');
388-
expect(stackframes.body.stackFrames[1].source!.path).to.be.equal(pythonFile, 'incorrect source file for main thread stack');
389-
} else {
390-
expect(thread.name).to.be.equal('foo', 'incorrect name for thread \'foo\'');
393+
expect(stackframes.body.stackFrames[0].line).to.be.equal(5);
394+
expect(stackframes.body.stackFrames[0].source!.path).to.be.equal(pythonFile);
395+
expect(stackframes.body.stackFrames[0].name).to.be.equal('foo');
391396

392-
expect(stackframes.body.stackFrames[0].line).to.be.equal(11, 'incorrect line number for foo thread stack');
393-
expect(stackframes.body.stackFrames[0].source!.path).to.be.equal(pythonFile, 'incorrect source file for foo thread stack');
397+
expect(stackframes.body.stackFrames[1].line).to.be.equal(8);
398+
expect(stackframes.body.stackFrames[1].source!.path).to.be.equal(pythonFile);
399+
expect(stackframes.body.stackFrames[1].name).to.be.equal('bar');
394400

395-
expect(stackframes.body.stackFrames[1].line).to.be.equal(13, 'incorrect line number for foo thread stack');
396-
expect(stackframes.body.stackFrames[1].source!.path).to.be.equal(pythonFile, 'incorrect source file for foo thread stack');
397-
}
398-
}
401+
expect(stackframes.body.stackFrames[2].line).to.be.equal(10);
402+
expect(stackframes.body.stackFrames[2].source!.path).to.be.equal(pythonFile);
399403
});
400404
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import time
2+
3+
def foo():
4+
time.sleep(3)
5+
print(1)
6+
7+
def bar():
8+
foo()
9+
10+
bar()

0 commit comments

Comments
 (0)