11var common = require ( '../common' ) ;
22var assert = require ( 'assert' ) ;
3- var d = require ( '_debugger' ) ;
3+ var debug = require ( '_debugger' ) ;
44
55var spawn = require ( 'child_process' ) . spawn ;
66
77
88var resCount = 0 ;
9- var p = new d . Protocol ( ) ;
9+ var p = new debug . Protocol ( ) ;
1010p . onResponse = function ( res ) {
1111 resCount ++ ;
1212} ;
@@ -18,46 +18,48 @@ p.execute("Type: connect\r\n" +
1818 "Content-Length: 0\r\n\r\n" ) ;
1919assert . equal ( 1 , resCount ) ;
2020
21- var n = spawn ( process . execPath ,
22- [ '-e' , 'setInterval(function () { console.log("blah"); }, 1000);' ] ) ;
2321
22+ var connectCount = 0 ;
2423
25- var connected = false ;
24+ function test ( cb ) {
25+ var nodeProcess = spawn ( process . execPath ,
26+ [ '-e' , 'setInterval(function () { console.log("blah"); }, 1000);' ] ) ;
2627
27- n . stdout . once ( 'data' , function ( ) {
28- console . log ( "new node process: %d" , n . pid ) ;
29- process . kill ( n . pid , "SIGUSR1" ) ;
30- console . log ( "signaling it with SIGUSR1" ) ;
31-
32- } ) ;
28+ nodeProcess . stdout . once ( 'data' , function ( ) {
29+ console . log ( "new node process: %d" , nodeProcess . pid ) ;
30+ process . kill ( nodeProcess . pid , "SIGUSR1" ) ;
31+ console . log ( "signaling it with SIGUSR1" ) ;
32+ } ) ;
3333
34- var didTryConnect = false ;
35- n . stderr . setEncoding ( 'utf8' ) ;
36- n . stderr . on ( 'data' , function ( d ) {
37- if ( didTryConnect == false && / d e b u g g e r / . test ( d ) ) {
38- didTryConnect = true ;
39- tryConnect ( ) ;
40- }
41- } )
42-
43-
44- function tryConnect ( ) {
45- // Wait for some data before trying to connect
46- var c = new d . Client ( ) ;
47- process . stdout . write ( "connecting..." ) ;
48- c . connect ( d . port , function ( ) {
49- connected = true ;
50- console . log ( "connected!" ) ;
34+ var didTryConnect = false ;
35+ nodeProcess . stderr . setEncoding ( 'utf8' ) ;
36+ nodeProcess . stderr . on ( 'data' , function ( data ) {
37+ if ( didTryConnect == false && / d e b u g g e r / . test ( data ) ) {
38+ didTryConnect = true ;
39+
40+ // Wait for some data before trying to connect
41+ var c = new debug . Client ( ) ;
42+ process . stdout . write ( "connecting..." ) ;
43+ c . connect ( debug . port , function ( ) {
44+ connectCount ++ ;
45+ console . log ( "connected!" ) ;
46+ cb ( c , nodeProcess ) ;
47+ } ) ;
48+ }
5149 } ) ;
50+ }
5251
53- c . reqVersion ( function ( v ) {
52+
53+ test ( function ( client , nodeProcess ) {
54+ client . reqVersion ( function ( v ) {
55+ console . log ( "version: %s" , v ) ;
5456 assert . equal ( process . versions . v8 , v ) ;
55- n . kill ( ) ;
57+ nodeProcess . kill ( ) ;
5658 } ) ;
57- }
59+ } ) ;
5860
5961
6062process . on ( 'exit' , function ( ) {
61- assert . ok ( connected ) ;
63+ assert . equal ( 1 , connectCount ) ;
6264} ) ;
6365
0 commit comments