Skip to content

Commit c483263

Browse files
committed
improvements to multi threaded tests
1 parent 99f5034 commit c483263

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

src/test/debugger/misc.test.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
// tslint:disable:no-suspicious-comment max-func-body-length no-invalid-this no-var-requires no-require-imports no-any
55

6-
import { expect, use } from 'chai';
7-
import * as chaiAsPromised from 'chai-as-promised';
6+
import { expect } from 'chai';
87
import * as path from 'path';
98
import { ThreadEvent } from 'vscode-debugadapter';
109
import { DebugClient } from 'vscode-debugadapter-testsupport';
@@ -22,8 +21,6 @@ import { DebugClientEx } from './debugClient';
2221

2322
const isProcessRunning = require('is-running') as (number) => boolean;
2423

25-
use(chaiAsPromised);
26-
2724
const debugFilesPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'debugging');
2825

2926
const DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'debugger', 'Main.js');
@@ -446,7 +443,11 @@ let testCounter = 0;
446443
await debugClient.assertStoppedLocation('exception', pauseLocation);
447444
});
448445
test('Test multi-threaded debugging', async function () {
449-
this.timeout(30000);
446+
if (debuggerType !== 'python') {
447+
// See GitHub issue #1250
448+
this.skip();
449+
return;
450+
}
450451
await Promise.all([
451452
debugClient.configurationSequence(),
452453
debugClient.launch(buildLauncArgs('multiThread.py', false)),
@@ -470,6 +471,49 @@ let testCounter = 0;
470471
expect(thread.id).to.be.lessThan(MAX_SIGNED_INT32 + 1, 'ThreadId is not an integer');
471472
}
472473
});
474+
test('Test multi-threaded debugging', async function () {
475+
this.timeout(30000);
476+
await Promise.all([
477+
debugClient.launch(buildLauncArgs('multiThread.py', false)),
478+
debugClient.waitForEvent('initialized')
479+
]);
480+
481+
const pythonFile = path.join(debugFilesPath, 'multiThread.py');
482+
const breakpointLocation = { path: pythonFile, column: 1, line: 11 };
483+
const breakpointRequestArgs = {
484+
lines: [breakpointLocation.line],
485+
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
486+
source: { path: breakpointLocation.path }
487+
};
488+
489+
function waitForStoppedEventFromTwoThreads() {
490+
return new Promise((resolve, reject) => {
491+
let numberOfStops = 0;
492+
debugClient.addListener('stopped', (event: DebugProtocol.StoppedEvent) => {
493+
numberOfStops += 1;
494+
if (numberOfStops < 2) {
495+
return;
496+
}
497+
resolve(event);
498+
});
499+
setTimeout(() => reject(new Error('Timeout waiting for two threads to stop at breakpoint')), DEBUGGER_TIMEOUT);
500+
});
501+
}
502+
503+
await Promise.all([
504+
debugClient.setBreakpointsRequest(breakpointRequestArgs),
505+
debugClient.setExceptionBreakpointsRequest({ filters: [] }),
506+
debugClient.configurationDoneRequest(),
507+
waitForStoppedEventFromTwoThreads(),
508+
debugClient.assertStoppedLocation('breakpoint', breakpointLocation)
509+
]);
510+
511+
const threads = await debugClient.threadsRequest();
512+
expect(threads.body.threads).of.lengthOf(2, 'incorrect number of threads');
513+
for (const thread of threads.body.threads) {
514+
expect(thread.id).to.be.lessThan(MAX_SIGNED_INT32 + 1, 'ThreadId is not an integer');
515+
}
516+
});
473517
test('Test stack frames', async () => {
474518
await Promise.all([
475519
debugClient.configurationSequence(),

0 commit comments

Comments
 (0)