@@ -28,14 +28,14 @@ const assert = require('assert');
2828const dgram = require ( 'dgram' ) ;
2929const util = require ( 'util' ) ;
3030const networkInterfaces = require ( 'os' ) . networkInterfaces ( ) ;
31- const fork = require ( 'child_process' ) . fork ;
31+ const { fork } = require ( 'child_process' ) ;
3232const LOCAL_BROADCAST_HOST = '255.255.255.255' ;
3333const TIMEOUT = common . platformTimeout ( 5000 ) ;
3434const messages = [
3535 Buffer . from ( 'First message to send' ) ,
3636 Buffer . from ( 'Second message to send' ) ,
3737 Buffer . from ( 'Third message to send' ) ,
38- Buffer . from ( 'Fourth message to send' )
38+ Buffer . from ( 'Fourth message to send' ) ,
3939] ;
4040
4141let bindAddress = null ;
@@ -65,7 +65,7 @@ if (process.argv[2] !== 'child') {
6565 let timer = null ;
6666
6767 // Exit the test if it doesn't succeed within TIMEOUT
68- timer = setTimeout ( function ( ) {
68+ timer = setTimeout ( ( ) => {
6969 console . error ( '[PARENT] Responses were not received within %d ms.' ,
7070 TIMEOUT ) ;
7171 console . error ( '[PARENT] Fail' ) ;
@@ -84,7 +84,7 @@ if (process.argv[2] !== 'child') {
8484 worker . messagesReceived = [ ] ;
8585
8686 // Handle the death of workers
87- worker . on ( 'exit' , function ( code , signal ) {
87+ worker . on ( 'exit' , ( code , signal ) => {
8888 // Don't consider this the true death if the worker
8989 // has finished successfully
9090 // or if the exit code is 0
@@ -98,6 +98,8 @@ if (process.argv[2] !== 'child') {
9898 dead ,
9999 listeners ) ;
100100
101+ assert . notStrictEqual ( signal , null ) ;
102+
101103 if ( dead === listeners ) {
102104 console . error ( '[PARENT] All workers have died.' ) ;
103105 console . error ( '[PARENT] Fail' ) ;
@@ -108,7 +110,7 @@ if (process.argv[2] !== 'child') {
108110 }
109111 } ) ;
110112
111- worker . on ( 'message' , function ( msg ) {
113+ worker . on ( 'message' , ( msg ) => {
112114 if ( msg . listening ) {
113115 listening += 1 ;
114116
@@ -132,12 +134,12 @@ if (process.argv[2] !== 'child') {
132134 'required number of ' +
133135 'messages. Will now compare.' ) ;
134136
135- Object . keys ( workers ) . forEach ( function ( pid ) {
137+ Object . keys ( workers ) . forEach ( ( pid ) => {
136138 const worker = workers [ pid ] ;
137139
138140 let count = 0 ;
139141
140- worker . messagesReceived . forEach ( function ( buf ) {
142+ worker . messagesReceived . forEach ( ( buf ) => {
141143 for ( let i = 0 ; i < messages . length ; ++ i ) {
142144 if ( buf . toString ( ) === messages [ i ] . toString ( ) ) {
143145 count ++ ;
@@ -170,11 +172,11 @@ if (process.argv[2] !== 'child') {
170172 // Bind the address explicitly for sending
171173 // INADDR_BROADCAST to only one interface
172174 sendSocket . bind ( common . PORT , bindAddress ) ;
173- sendSocket . on ( 'listening' , function ( ) {
175+ sendSocket . on ( 'listening' , ( ) => {
174176 sendSocket . setBroadcast ( true ) ;
175177 } ) ;
176178
177- sendSocket . on ( 'close' , function ( ) {
179+ sendSocket . on ( 'close' , ( ) => {
178180 console . error ( '[PARENT] sendSocket closed' ) ;
179181 } ) ;
180182
@@ -192,7 +194,7 @@ if (process.argv[2] !== 'child') {
192194 buf . length ,
193195 common . PORT ,
194196 LOCAL_BROADCAST_HOST ,
195- function ( err ) {
197+ ( err ) => {
196198 assert . ifError ( err ) ;
197199 console . error ( '[PARENT] sent %s to %s:%s' ,
198200 util . inspect ( buf . toString ( ) ) ,
@@ -204,7 +206,7 @@ if (process.argv[2] !== 'child') {
204206 } ;
205207
206208 function killSubprocesses ( subprocesses ) {
207- Object . keys ( subprocesses ) . forEach ( function ( key ) {
209+ Object . keys ( subprocesses ) . forEach ( ( key ) => {
208210 const subprocess = subprocesses [ key ] ;
209211 subprocess . kill ( ) ;
210212 } ) ;
@@ -218,7 +220,7 @@ if (process.argv[2] === 'child') {
218220 reuseAddr : true
219221 } ) ;
220222
221- listenSocket . on ( 'message' , function ( buf , rinfo ) {
223+ listenSocket . on ( 'message' , ( buf , rinfo ) => {
222224 // Receive udp messages only sent from parent
223225 if ( rinfo . address !== bindAddress ) return ;
224226
@@ -232,24 +234,18 @@ if (process.argv[2] === 'child') {
232234 process . send ( { message : buf . toString ( ) } ) ;
233235
234236 if ( receivedMessages . length === messages . length ) {
235- process . nextTick ( function ( ) {
236- listenSocket . close ( ) ;
237- } ) ;
237+ process . nextTick ( ( ) => { listenSocket . close ( ) ; } ) ;
238238 }
239239 } ) ;
240240
241- listenSocket . on ( 'close' , function ( ) {
241+ listenSocket . on ( 'close' , ( ) => {
242242 // HACK: Wait to exit the process to ensure that the parent
243243 // process has had time to receive all messages via process.send()
244244 // This may be indicative of some other issue.
245- setTimeout ( function ( ) {
246- process . exit ( ) ;
247- } , 1000 ) ;
245+ setTimeout ( ( ) => { process . exit ( ) ; } , 1000 ) ;
248246 } ) ;
249247
250- listenSocket . on ( 'listening' , function ( ) {
251- process . send ( { listening : true } ) ;
252- } ) ;
248+ listenSocket . on ( 'listening' , ( ) => { process . send ( { listening : true } ) ; } ) ;
253249
254250 listenSocket . bind ( common . PORT ) ;
255251}
0 commit comments