11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4- import { expect , use } from 'chai' ;
5- import * as chaiAsPromised from 'chai-as-promised' ;
4+ import { expect } from 'chai' ;
65import { ChildProcess } from 'child_process' ;
76import * as getFreePort from 'get-port' ;
8- import { EOL } from 'os' ;
97import * as path from 'path' ;
10- import { ThreadEvent } from 'vscode-debugadapter' ;
118import { DebugClient } from 'vscode-debugadapter-testsupport' ;
129import { createDeferred } from '../../client/common/helpers' ;
1310import { BufferDecoder } from '../../client/common/process/decoder' ;
1411import { ProcessService } from '../../client/common/process/proc' ;
1512import { AttachRequestArguments } from '../../client/debugger/Common/Contracts' ;
1613import { initialize } from '../initialize' ;
1714
18- use ( chaiAsPromised ) ;
15+ // tslint:disable:max-func-body-length no-empty
1916
2017const fileToDebug = path . join ( __dirname , '..' , '..' , '..' , 'src' , 'testMultiRootWkspc' , 'workspace5' , 'remoteDebugger.py' ) ;
2118const ptvsdPath = path . join ( __dirname , '..' , '..' , '..' , 'pythonFiles' , 'PythonTools' ) ;
2219const DEBUG_ADAPTER = path . join ( __dirname , '..' , '..' , 'client' , 'debugger' , 'Main.js' ) ;
2320
24- // tslint:disable-next-line:max-func-body-length
2521suite ( 'Attach Debugger' , ( ) => {
2622 let debugClient : DebugClient ;
2723 let procToKill : ChildProcess ;
28- suiteSetup ( function ( ) {
29- // tslint:disable-next-line:no-invalid-this
30- this . skip ( ) ;
31- return initialize ( ) ;
32- } ) ;
24+ suiteSetup ( initialize ) ;
3325
3426 setup ( async ( ) => {
3527 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
@@ -40,11 +32,12 @@ suite('Attach Debugger', () => {
4032 // Wait for a second before starting another test (sometimes, sockets take a while to get closed).
4133 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
4234 try {
43- debugClient . stop ( ) ;
44- // tslint:disable-next-line:no-empty
35+ await debugClient . stop ( ) . catch ( ( ) => { } ) ;
4536 } catch ( ex ) { }
4637 if ( procToKill ) {
47- procToKill . kill ( ) ;
38+ try {
39+ procToKill . kill ( ) ;
40+ } catch { }
4841 }
4942 } ) ;
5043 test ( 'Confirm we are able to attach to a running program' , async ( ) => {
@@ -66,35 +59,23 @@ suite('Attach Debugger', () => {
6659 const result = procService . execObservable ( 'python' , [ fileToDebug , port . toString ( ) ] , { env : customEnv , cwd : path . dirname ( fileToDebug ) } ) ;
6760 procToKill = result . proc ;
6861
69- const completed = createDeferred ( ) ;
7062 const expectedOutputs = [
7163 { value : 'start' , deferred : createDeferred ( ) } ,
72- { value : 'Peter Smith ' , deferred : createDeferred ( ) } ,
64+ { value : 'attached ' , deferred : createDeferred ( ) } ,
7365 { value : 'end' , deferred : createDeferred ( ) }
7466 ] ;
7567 const startOutputReceived = expectedOutputs [ 0 ] . deferred . promise ;
76- const firstOutputReceived = expectedOutputs [ 1 ] . deferred . promise ;
77- const secondOutputReceived = expectedOutputs [ 2 ] . deferred . promise ;
68+ const attachedOutputReceived = expectedOutputs [ 1 ] . deferred . promise ;
69+ const lastOutputReceived = expectedOutputs [ 2 ] . deferred . promise ;
7870
7971 result . out . subscribe ( output => {
8072 if ( expectedOutputs [ 0 ] . value === output . out ) {
8173 expectedOutputs . shift ( ) ! . deferred . resolve ( ) ;
8274 }
83- } , ex => {
84- completed . reject ( ex ) ;
85- } , ( ) => {
86- completed . resolve ( ) ;
8775 } ) ;
8876
8977 await startOutputReceived ;
9078
91- const threadIdPromise = createDeferred < number > ( ) ;
92- debugClient . on ( 'thread' , ( data : ThreadEvent ) => {
93- if ( data . body . reason === 'started' ) {
94- threadIdPromise . resolve ( data . body . threadId ) ;
95- }
96- } ) ;
97-
9879 const initializePromise = debugClient . initializeRequest ( {
9980 adapterID : 'python' ,
10081 linesStartAt1 : true ,
@@ -105,21 +86,28 @@ suite('Attach Debugger', () => {
10586 await debugClient . attachRequest ( args ) ;
10687 await initializePromise ;
10788
108- // Wait till we get the thread of the program.
109- const threadId = await threadIdPromise . promise ;
110- expect ( threadId ) . to . be . greaterThan ( 0 , 'ThreadId not received' ) ;
89+ // Wait till we attach.
90+ await attachedOutputReceived ;
11191
112- // Continue the program.
113- await debugClient . continueRequest ( { threadId } ) ;
92+ // Add a breakpoint.
93+ const breakpointLocation = { path : fileToDebug , column : 0 , line : 16 } ;
94+ await debugClient . setBreakpointsRequest ( {
95+ lines : [ breakpointLocation . line ] ,
96+ breakpoints : [ { line : breakpointLocation . line , column : breakpointLocation . column } ] ,
97+ source : { path : breakpointLocation . path }
98+ } ) ;
11499
115- // Value for input prompt.
116- result . proc . stdin . write ( `Peter Smith${ EOL } ` ) ;
117- await firstOutputReceived ;
100+ await debugClient . assertStoppedLocation ( 'breakpoint' , breakpointLocation ) ;
118101
119- result . proc . stdin . write ( `${ EOL } ` ) ;
120- await secondOutputReceived ;
121- await completed . promise ;
102+ // Get thread to continue.
103+ const threads = await debugClient . threadsRequest ( ) ;
104+ expect ( threads ) . to . be . not . equal ( undefined , 'no threads response' ) ;
105+ expect ( threads . body . threads ) . to . be . lengthOf ( 1 ) ;
106+
107+ // Continue the program.
108+ await debugClient . continueRequest ( { threadId : threads . body . threads [ 0 ] . id } ) ;
122109
110+ await lastOutputReceived ;
123111 await debugClient . waitForEvent ( 'terminated' ) ;
124112 } ) ;
125113} ) ;
0 commit comments