11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
4- var cluster = require ( 'cluster' ) ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const cluster = require ( 'cluster' ) ;
55
6- assert . equal ( 'NODE_UNIQUE_ID' in process . env , false ,
7- 'NODE_UNIQUE_ID should be removed on startup' ) ;
6+ assert . strictEqual ( 'NODE_UNIQUE_ID' in process . env , false ,
7+ 'NODE_UNIQUE_ID should be removed on startup' ) ;
88
99function forEach ( obj , fn ) {
10- Object . keys ( obj ) . forEach ( function ( name , index ) {
10+ Object . keys ( obj ) . forEach ( ( name , index ) => {
1111 fn ( obj [ name ] , name , index ) ;
1212 } ) ;
1313}
1414
1515
1616if ( cluster . isWorker ) {
17- var http = require ( 'http' ) ;
17+ const http = require ( 'http' ) ;
1818 http . Server ( function ( ) {
1919
2020 } ) . listen ( common . PORT , '127.0.0.1' ) ;
2121} else if ( cluster . isMaster ) {
2222
23- var checks = {
23+ const checks = {
2424 cluster : {
2525 events : {
2626 fork : false ,
@@ -57,13 +57,13 @@ if (cluster.isWorker) {
5757 } ;
5858
5959 var worker ;
60- var stateNames = Object . keys ( checks . worker . states ) ;
60+ const stateNames = Object . keys ( checks . worker . states ) ;
6161
6262 //Check events, states, and emit arguments
63- forEach ( checks . cluster . events , function ( bool , name , index ) {
63+ forEach ( checks . cluster . events , ( bool , name , index ) => {
6464
6565 //Listen on event
66- cluster . on ( name , function ( /* worker */ ) {
66+ cluster . on ( name , common . mustCall ( function ( /* worker */ ) {
6767
6868 //Set event
6969 checks . cluster . events [ name ] = true ;
@@ -74,28 +74,26 @@ if (cluster.isWorker) {
7474 //Check state
7575 var state = stateNames [ index ] ;
7676 checks . worker . states [ state ] = ( state === worker . state ) ;
77- } ) ;
77+ } ) ) ;
7878 } ) ;
7979
8080 //Kill worker when listening
81- cluster . on ( 'listening' , function ( ) {
81+ cluster . on ( 'listening' , common . mustCall ( ( ) => {
8282 worker . kill ( ) ;
83- } ) ;
83+ } ) ) ;
8484
8585 //Kill process when worker is killed
86- cluster . on ( 'exit' , function ( ) {
87- process . exit ( 0 ) ;
88- } ) ;
86+ cluster . on ( 'exit' , common . mustCall ( ( ) => { } ) ) ;
8987
9088 //Create worker
9189 worker = cluster . fork ( ) ;
92- assert . equal ( worker . id , 1 ) ;
93- assert . ok ( worker instanceof cluster . Worker ,
94- 'the worker is not a instance of the Worker constructor' ) ;
90+ assert . strictEqual ( worker . id , 1 ) ;
91+ assert ( worker instanceof cluster . Worker ,
92+ 'the worker is not a instance of the Worker constructor' ) ;
9593
9694 //Check event
9795 forEach ( checks . worker . events , function ( bool , name , index ) {
98- worker . on ( name , function ( ) {
96+ worker . on ( name , common . mustCall ( function ( ) {
9997 //Set event
10098 checks . worker . events [ name ] = true ;
10199
@@ -104,56 +102,57 @@ if (cluster.isWorker) {
104102
105103 switch ( name ) {
106104 case 'exit' :
107- assert . equal ( arguments [ 0 ] , worker . process . exitCode ) ;
108- assert . equal ( arguments [ 1 ] , worker . process . signalCode ) ;
109- assert . equal ( arguments . length , 2 ) ;
105+ assert . strictEqual ( arguments [ 0 ] , worker . process . exitCode ) ;
106+ assert . strictEqual ( arguments [ 1 ] , worker . process . signalCode ) ;
107+ assert . strictEqual ( arguments . length , 2 ) ;
110108 break ;
111109
112110 case 'listening' :
113- assert . equal ( arguments . length , 1 ) ;
114- var expect = { address : '127.0.0.1' ,
115- port : common . PORT ,
116- addressType : 4 ,
117- fd : undefined } ;
111+ assert . strictEqual ( arguments . length , 1 ) ;
112+ const expect = { address : '127.0.0.1' ,
113+ port : common . PORT ,
114+ addressType : 4 ,
115+ fd : undefined } ;
118116 assert . deepStrictEqual ( arguments [ 0 ] , expect ) ;
119117 break ;
120118
121119 default :
122- assert . equal ( arguments . length , 0 ) ;
120+ assert . strictEqual ( arguments . length , 0 ) ;
123121 break ;
124122 }
125- } ) ;
123+ } ) ) ;
126124 } ) ;
127125
128126 //Check all values
129- process . once ( 'exit' , function ( ) {
127+ process . once ( 'exit' , ( ) => {
130128 //Check cluster events
131- forEach ( checks . cluster . events , function ( check , name ) {
132- assert . ok ( check , 'The cluster event "' + name + '" on the cluster ' +
133- ' object did not fire' ) ;
129+ forEach ( checks . cluster . events , ( check , name ) => {
130+ assert ( check ,
131+ `The cluster event " ${ name } " on the cluster object did not fire` ) ;
134132 } ) ;
135133
136134 //Check cluster event arguments
137- forEach ( checks . cluster . equal , function ( check , name ) {
138- assert . ok ( check , 'The cluster event "' + name + '" did not emit ' +
139- ' with correct argument' ) ;
135+ forEach ( checks . cluster . equal , ( check , name ) => {
136+ assert ( check ,
137+ `The cluster event " ${ name } " did not emit with correct argument` ) ;
140138 } ) ;
141139
142140 //Check worker states
143- forEach ( checks . worker . states , function ( check , name ) {
144- assert . ok ( check , 'The worker state "' + name + '" was not set to true' ) ;
141+ forEach ( checks . worker . states , ( check , name ) => {
142+ assert ( check ,
143+ `The worker state "${ name } " was not set to true` ) ;
145144 } ) ;
146145
147146 //Check worker events
148- forEach ( checks . worker . events , function ( check , name ) {
149- assert . ok ( check , 'The worker event "' + name + '" on the worker object ' +
150- ' did not fire' ) ;
147+ forEach ( checks . worker . events , ( check , name ) => {
148+ assert ( check ,
149+ `The worker event " ${ name } " on the worker object did not fire` ) ;
151150 } ) ;
152151
153152 //Check worker event arguments
154- forEach ( checks . worker . equal , function ( check , name ) {
155- assert . ok ( check , 'The worker event "' + name + '" did not emit with ' +
156- 'corrent argument' ) ;
153+ forEach ( checks . worker . equal , ( check , name ) => {
154+ assert ( check ,
155+ `The worker event " ${ name } " did not emit with correct argument` ) ;
157156 } ) ;
158157 } ) ;
159158
0 commit comments