3
3
4
4
// tslint:disable:no-suspicious-comment max-func-body-length no-invalid-this no-var-requires no-require-imports no-any
5
5
6
- import { expect , use } from 'chai' ;
7
- import * as chaiAsPromised from 'chai-as-promised' ;
6
+ import { expect } from 'chai' ;
8
7
import * as path from 'path' ;
9
8
import { ThreadEvent } from 'vscode-debugadapter' ;
10
9
import { DebugClient } from 'vscode-debugadapter-testsupport' ;
@@ -22,8 +21,6 @@ import { DebugClientEx } from './debugClient';
22
21
23
22
const isProcessRunning = require ( 'is-running' ) as ( number ) = > boolean ;
24
23
25
- use ( chaiAsPromised ) ;
26
-
27
24
const debugFilesPath = path . join ( __dirname , '..' , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'debugging' ) ;
28
25
29
26
const DEBUG_ADAPTER = path . join ( __dirname , '..' , '..' , 'client' , 'debugger' , 'Main.js' ) ;
@@ -445,12 +442,20 @@ let testCounter = 0;
445
442
const pauseLocation = { path : path . join ( debugFilesPath , 'sample3WithEx.py' ) , line : 5 } ;
446
443
await debugClient . assertStoppedLocation ( 'exception' , pauseLocation ) ;
447
444
} ) ;
448
- test ( 'Test multi-threaded debugging' , async ( ) => {
445
+ test ( 'Test multi-threaded debugging' , async function ( ) {
446
+ if ( debuggerType !== 'python' ) {
447
+ // See GitHub issue #1250
448
+ this . skip ( ) ;
449
+ return ;
450
+ }
449
451
await Promise . all ( [
450
452
debugClient . configurationSequence ( ) ,
451
453
debugClient . launch ( buildLauncArgs ( 'multiThread.py' , false ) ) ,
452
454
debugClient . waitForEvent ( 'initialized' )
453
455
] ) ;
456
+
457
+ // Add a delay for debugger to start (sometimes it takes a long time for new debugger to break).
458
+ await sleep ( 3000 ) ;
454
459
const pythonFile = path . join ( debugFilesPath , 'multiThread.py' ) ;
455
460
const breakpointLocation = { path : pythonFile , column : 1 , line : 11 } ;
456
461
await debugClient . setBreakpointsRequest ( {
@@ -459,8 +464,49 @@ let testCounter = 0;
459
464
source : { path : breakpointLocation . path }
460
465
} ) ;
461
466
462
- // hit breakpoint.
463
467
await debugClient . assertStoppedLocation ( 'breakpoint' , breakpointLocation ) ;
468
+ const threads = await debugClient . threadsRequest ( ) ;
469
+ expect ( threads . body . threads ) . of . lengthOf ( 2 , 'incorrect number of threads' ) ;
470
+ for ( const thread of threads . body . threads ) {
471
+ expect ( thread . id ) . to . be . lessThan ( MAX_SIGNED_INT32 + 1 , 'ThreadId is not an integer' ) ;
472
+ }
473
+ } ) ;
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
+ ] ) ;
464
510
465
511
const threads = await debugClient . threadsRequest ( ) ;
466
512
expect ( threads . body . threads ) . of . lengthOf ( 2 , 'incorrect number of threads' ) ;
0 commit comments