@@ -28,14 +28,14 @@ const assert = require('assert');
28
28
const dgram = require ( 'dgram' ) ;
29
29
const util = require ( 'util' ) ;
30
30
const networkInterfaces = require ( 'os' ) . networkInterfaces ( ) ;
31
- const fork = require ( 'child_process' ) . fork ;
31
+ const { fork } = require ( 'child_process' ) ;
32
32
const LOCAL_BROADCAST_HOST = '255.255.255.255' ;
33
33
const TIMEOUT = common . platformTimeout ( 5000 ) ;
34
34
const messages = [
35
35
Buffer . from ( 'First message to send' ) ,
36
36
Buffer . from ( 'Second message to send' ) ,
37
37
Buffer . from ( 'Third message to send' ) ,
38
- Buffer . from ( 'Fourth message to send' )
38
+ Buffer . from ( 'Fourth message to send' ) ,
39
39
] ;
40
40
41
41
let bindAddress = null ;
@@ -65,7 +65,7 @@ if (process.argv[2] !== 'child') {
65
65
let timer = null ;
66
66
67
67
// Exit the test if it doesn't succeed within TIMEOUT
68
- timer = setTimeout ( function ( ) {
68
+ timer = setTimeout ( ( ) => {
69
69
console . error ( '[PARENT] Responses were not received within %d ms.' ,
70
70
TIMEOUT ) ;
71
71
console . error ( '[PARENT] Fail' ) ;
@@ -84,7 +84,7 @@ if (process.argv[2] !== 'child') {
84
84
worker . messagesReceived = [ ] ;
85
85
86
86
// Handle the death of workers
87
- worker . on ( 'exit' , function ( code , signal ) {
87
+ worker . on ( 'exit' , ( code , signal ) => {
88
88
// Don't consider this the true death if the worker
89
89
// has finished successfully
90
90
// or if the exit code is 0
@@ -98,6 +98,8 @@ if (process.argv[2] !== 'child') {
98
98
dead ,
99
99
listeners ) ;
100
100
101
+ assert . notStrictEqual ( signal , null ) ;
102
+
101
103
if ( dead === listeners ) {
102
104
console . error ( '[PARENT] All workers have died.' ) ;
103
105
console . error ( '[PARENT] Fail' ) ;
@@ -108,7 +110,7 @@ if (process.argv[2] !== 'child') {
108
110
}
109
111
} ) ;
110
112
111
- worker . on ( 'message' , function ( msg ) {
113
+ worker . on ( 'message' , ( msg ) => {
112
114
if ( msg . listening ) {
113
115
listening += 1 ;
114
116
@@ -132,12 +134,12 @@ if (process.argv[2] !== 'child') {
132
134
'required number of ' +
133
135
'messages. Will now compare.' ) ;
134
136
135
- Object . keys ( workers ) . forEach ( function ( pid ) {
137
+ Object . keys ( workers ) . forEach ( ( pid ) => {
136
138
const worker = workers [ pid ] ;
137
139
138
140
let count = 0 ;
139
141
140
- worker . messagesReceived . forEach ( function ( buf ) {
142
+ worker . messagesReceived . forEach ( ( buf ) => {
141
143
for ( let i = 0 ; i < messages . length ; ++ i ) {
142
144
if ( buf . toString ( ) === messages [ i ] . toString ( ) ) {
143
145
count ++ ;
@@ -170,11 +172,11 @@ if (process.argv[2] !== 'child') {
170
172
// Bind the address explicitly for sending
171
173
// INADDR_BROADCAST to only one interface
172
174
sendSocket . bind ( common . PORT , bindAddress ) ;
173
- sendSocket . on ( 'listening' , function ( ) {
175
+ sendSocket . on ( 'listening' , ( ) => {
174
176
sendSocket . setBroadcast ( true ) ;
175
177
} ) ;
176
178
177
- sendSocket . on ( 'close' , function ( ) {
179
+ sendSocket . on ( 'close' , ( ) => {
178
180
console . error ( '[PARENT] sendSocket closed' ) ;
179
181
} ) ;
180
182
@@ -192,7 +194,7 @@ if (process.argv[2] !== 'child') {
192
194
buf . length ,
193
195
common . PORT ,
194
196
LOCAL_BROADCAST_HOST ,
195
- function ( err ) {
197
+ ( err ) => {
196
198
assert . ifError ( err ) ;
197
199
console . error ( '[PARENT] sent %s to %s:%s' ,
198
200
util . inspect ( buf . toString ( ) ) ,
@@ -204,7 +206,7 @@ if (process.argv[2] !== 'child') {
204
206
} ;
205
207
206
208
function killSubprocesses ( subprocesses ) {
207
- Object . keys ( subprocesses ) . forEach ( function ( key ) {
209
+ Object . keys ( subprocesses ) . forEach ( ( key ) => {
208
210
const subprocess = subprocesses [ key ] ;
209
211
subprocess . kill ( ) ;
210
212
} ) ;
@@ -218,7 +220,7 @@ if (process.argv[2] === 'child') {
218
220
reuseAddr : true
219
221
} ) ;
220
222
221
- listenSocket . on ( 'message' , function ( buf , rinfo ) {
223
+ listenSocket . on ( 'message' , ( buf , rinfo ) => {
222
224
// Receive udp messages only sent from parent
223
225
if ( rinfo . address !== bindAddress ) return ;
224
226
@@ -232,24 +234,18 @@ if (process.argv[2] === 'child') {
232
234
process . send ( { message : buf . toString ( ) } ) ;
233
235
234
236
if ( receivedMessages . length === messages . length ) {
235
- process . nextTick ( function ( ) {
236
- listenSocket . close ( ) ;
237
- } ) ;
237
+ process . nextTick ( ( ) => { listenSocket . close ( ) ; } ) ;
238
238
}
239
239
} ) ;
240
240
241
- listenSocket . on ( 'close' , function ( ) {
241
+ listenSocket . on ( 'close' , ( ) => {
242
242
// HACK: Wait to exit the process to ensure that the parent
243
243
// process has had time to receive all messages via process.send()
244
244
// This may be indicative of some other issue.
245
- setTimeout ( function ( ) {
246
- process . exit ( ) ;
247
- } , 1000 ) ;
245
+ setTimeout ( ( ) => { process . exit ( ) ; } , 1000 ) ;
248
246
} ) ;
249
247
250
- listenSocket . on ( 'listening' , function ( ) {
251
- process . send ( { listening : true } ) ;
252
- } ) ;
248
+ listenSocket . on ( 'listening' , ( ) => { process . send ( { listening : true } ) ; } ) ;
253
249
254
250
listenSocket . bind ( common . PORT ) ;
255
251
}
0 commit comments