@@ -35,32 +35,32 @@ var pids = null;
35
35
36
36
child . stderr . on ( 'data' , function ( data ) {
37
37
var lines = data . toString ( ) . replace ( / \r / g, '' ) . trim ( ) . split ( '\n' ) ;
38
- var line = lines [ 0 ] ;
39
38
40
- lines . forEach ( function ( ln ) { console . log ( '> ' + ln ) } ) ;
39
+ lines . forEach ( function ( line ) {
40
+ console . log ( '> ' + line ) ;
41
41
42
- if ( outputTimerId !== undefined )
43
- clearTimeout ( outputTimerId ) ;
42
+ if ( line === 'all workers are running' ) {
43
+ child . on ( 'message' , function ( msg ) {
44
+ if ( msg . type !== 'pids' )
45
+ return ;
44
46
45
- if ( waitingForDebuggers ) {
46
- outputLines = outputLines . concat ( lines ) ;
47
- outputTimerId = setTimeout ( onNoMoreLines , 800 ) ;
48
- } else if ( line === 'all workers are running' ) {
49
- child . on ( 'message' , function ( msg ) {
50
- if ( msg . type !== 'pids' )
51
- return ;
47
+ pids = msg . pids ;
48
+ console . error ( 'got pids %j' , pids ) ;
52
49
53
- pids = msg . pids ;
54
- console . error ( 'got pids %j' , pids ) ;
50
+ waitingForDebuggers = true ;
51
+ process . _debugProcess ( child . pid ) ;
52
+ } ) ;
55
53
56
- waitingForDebuggers = true ;
57
- process . _debugProcess ( child . pid ) ;
58
- } ) ;
54
+ child . send ( {
55
+ type : 'getpids'
56
+ } ) ;
57
+ } else if ( waitingForDebuggers ) {
58
+ outputLines . push ( line ) ;
59
+ }
59
60
60
- child . send ( {
61
- type : 'getpids'
62
- } ) ;
63
- }
61
+ } ) ;
62
+ if ( outputLines . length >= expectedLines . length )
63
+ onNoMoreLines ( ) ;
64
64
} ) ;
65
65
66
66
function onNoMoreLines ( ) {
@@ -70,24 +70,24 @@ function onNoMoreLines() {
70
70
71
71
setTimeout ( function testTimedOut ( ) {
72
72
assert ( false , 'test timed out.' ) ;
73
- } , 6000 ) ;
73
+ } , 6000 ) . unref ( ) ;
74
74
75
75
process . on ( 'exit' , function onExit ( ) {
76
76
pids . forEach ( function ( pid ) {
77
77
process . kill ( pid ) ;
78
78
} ) ;
79
79
} ) ;
80
80
81
- function assertOutputLines ( ) {
82
- var expectedLines = [
83
- 'Starting debugger agent.' ,
84
- 'Debugger listening on port ' + 5858 ,
85
- 'Starting debugger agent.' ,
86
- 'Debugger listening on port ' + 5859 ,
87
- 'Starting debugger agent.' ,
88
- 'Debugger listening on port ' + 5860 ,
89
- ] ;
81
+ var expectedLines = [
82
+ 'Starting debugger agent.' ,
83
+ 'Debugger listening on port ' + 5858 ,
84
+ 'Starting debugger agent.' ,
85
+ 'Debugger listening on port ' + 5859 ,
86
+ 'Starting debugger agent.' ,
87
+ 'Debugger listening on port ' + 5860 ,
88
+ ] ;
90
89
90
+ function assertOutputLines ( ) {
91
91
// Do not assume any particular order of output messages,
92
92
// since workers can take different amout of time to
93
93
// start up
0 commit comments