@@ -9,11 +9,12 @@ const fork = require('child_process').fork;
9
9
const net = require ( 'net' ) ;
10
10
11
11
const id = '' + process . argv [ 2 ] ;
12
+ const port = '' + process . argv [ 3 ] ;
12
13
13
14
if ( id === 'undefined' ) {
14
15
const server = net . createServer ( common . mustNotCall ( ) ) ;
15
- server . listen ( common . PORT , function ( ) {
16
- const worker = fork ( __filename , [ 'worker' ] ) ;
16
+ server . listen ( 0 , function ( ) {
17
+ const worker = fork ( __filename , [ 'worker' , server . address ( ) . port ] ) ;
17
18
worker . on ( 'message' , function ( msg ) {
18
19
if ( msg !== 'stop-listening' ) return ;
19
20
server . close ( function ( ) {
@@ -23,14 +24,14 @@ if (id === 'undefined') {
23
24
} ) ;
24
25
} else if ( id === 'worker' ) {
25
26
let server = net . createServer ( common . mustNotCall ( ) ) ;
26
- server . listen ( common . PORT , common . mustNotCall ( ) ) ;
27
+ server . listen ( port , common . mustNotCall ( ) ) ;
27
28
server . on ( 'error' , common . mustCall ( function ( e ) {
28
29
assert ( e . code , 'EADDRINUSE' ) ;
29
30
process . send ( 'stop-listening' ) ;
30
31
process . once ( 'message' , function ( msg ) {
31
32
if ( msg !== 'stopped-listening' ) return ;
32
33
server = net . createServer ( common . mustNotCall ( ) ) ;
33
- server . listen ( common . PORT , common . mustCall ( function ( ) {
34
+ server . listen ( port , common . mustCall ( function ( ) {
34
35
server . close ( ) ;
35
36
} ) ) ;
36
37
} ) ;
0 commit comments