Skip to content

Commit

Permalink
improvements to multi threaded tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Mar 30, 2018
1 parent d78ee71 commit a12cce6
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions src/test/debugger/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

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

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

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

use(chaiAsPromised);

const debugFilesPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'debugging');

const DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'debugger', 'Main.js');
Expand Down Expand Up @@ -446,7 +443,11 @@ let testCounter = 0;
await debugClient.assertStoppedLocation('exception', pauseLocation);
});
test('Test multi-threaded debugging', async function () {
this.timeout(30000);
if (debuggerType !== 'python') {
// See GitHub issue #1250
this.skip();
return;
}
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('multiThread.py', false)),
Expand All @@ -470,6 +471,49 @@ let testCounter = 0;
expect(thread.id).to.be.lessThan(MAX_SIGNED_INT32 + 1, 'ThreadId is not an integer');
}
});
test('Test multi-threaded debugging', async function () {
this.timeout(30000);
await Promise.all([
debugClient.launch(buildLauncArgs('multiThread.py', false)),
debugClient.waitForEvent('initialized')
]);

const pythonFile = path.join(debugFilesPath, 'multiThread.py');
const breakpointLocation = { path: pythonFile, column: 1, line: 11 };
const breakpointRequestArgs = {
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
};

function waitForStoppedEventFromTwoThreads() {
return new Promise((resolve, reject) => {
let numberOfStops = 0;
debugClient.addListener('stopped', (event: DebugProtocol.StoppedEvent) => {
numberOfStops += 1;
if (numberOfStops < 2) {
return;
}
resolve(event);
});
setTimeout(() => reject(new Error('Timeout waiting for two threads to stop at breakpoint')), DEBUGGER_TIMEOUT);
});
}

await Promise.all([
debugClient.setBreakpointsRequest(breakpointRequestArgs),
debugClient.setExceptionBreakpointsRequest({ filters: [] }),
debugClient.configurationDoneRequest(),
waitForStoppedEventFromTwoThreads(),
debugClient.assertStoppedLocation('breakpoint', breakpointLocation)
]);

const threads = await debugClient.threadsRequest();
expect(threads.body.threads).of.lengthOf(2, 'incorrect number of threads');
for (const thread of threads.body.threads) {
expect(thread.id).to.be.lessThan(MAX_SIGNED_INT32 + 1, 'ThreadId is not an integer');
}
});
test('Test stack frames', async () => {
await Promise.all([
debugClient.configurationSequence(),
Expand Down

0 comments on commit a12cce6

Please sign in to comment.