@@ -3,47 +3,25 @@ var common = require('../common');
3
3
var assert = require ( 'assert' ) ;
4
4
var spawn = require ( 'child_process' ) . spawn ;
5
5
6
- var port = common . PORT + 1337 ;
6
+ const PORT_MIN = common . PORT + 1337 ;
7
+ const PORT_MAX = PORT_MIN + 2 ;
7
8
8
9
var args = [
9
- '--debug=' + port ,
10
+ '--debug=' + PORT_MIN ,
10
11
common . fixturesDir + '/clustered-server/app.js'
11
12
] ;
12
13
13
- var child = spawn ( process . execPath , args ) ;
14
- var outputLines = [ ] ;
14
+ const child = spawn ( process . execPath , args ) ;
15
+ child . stderr . setEncoding ( 'utf8' ) ;
15
16
16
- child . stderr . on ( 'data' , function ( data ) {
17
- var lines = data . toString ( ) . replace ( / \r / g, '' ) . trim ( ) . split ( '\n' ) ;
18
- var line = lines [ 0 ] ;
19
-
20
- lines . forEach ( function ( ln ) { console . log ( '> ' + ln ) ; } ) ;
21
-
22
- if ( line === 'all workers are running' ) {
23
- assertOutputLines ( ) ;
24
- process . exit ( ) ;
25
- } else {
26
- outputLines = outputLines . concat ( lines ) ;
27
- }
28
- } ) ;
29
-
30
- process . on ( 'exit' , function onExit ( ) {
31
- child . kill ( ) ;
17
+ let stderr = '' ;
18
+ child . stderr . on ( 'data' , data => {
19
+ stderr += data ;
20
+ if ( child . killed !== true && stderr . includes ( 'all workers are running' ) )
21
+ child . kill ( ) ;
32
22
} ) ;
33
23
34
- var assertOutputLines = common . mustCall ( function ( ) {
35
- var expectedLines = [
36
- 'Debugger listening on port ' + port ,
37
- 'Debugger listening on port ' + ( port + 1 ) ,
38
- 'Debugger listening on port ' + ( port + 2 ) ,
39
- ] ;
40
-
41
- // Do not assume any particular order of output messages,
42
- // since workers can take different amout of time to
43
- // start up
44
- outputLines . sort ( ) ;
45
-
46
- assert . equal ( outputLines . length , expectedLines . length ) ;
47
- for ( var i = 0 ; i < expectedLines . length ; i ++ )
48
- assert . equal ( outputLines [ i ] , expectedLines [ i ] ) ;
24
+ process . on ( 'exit' , ( ) => {
25
+ for ( let port = PORT_MIN ; port <= PORT_MAX ; port += 1 )
26
+ assert ( stderr . includes ( `Debugger listening on port ${ port } ` ) ) ;
49
27
} ) ;
0 commit comments