@@ -18,44 +18,6 @@ if (cluster.isWorker) {
18
18
19
19
} else if ( cluster . isMaster ) {
20
20
const KILL_SIGNAL = 'SIGKILL' ;
21
- const expectedResults = {
22
- emitDisconnect : {
23
- value : 1 ,
24
- message : "the worker did not emit 'disconnect'"
25
- } ,
26
- emitExit : {
27
- value : 1 ,
28
- message : "the worker did not emit 'exit'"
29
- } ,
30
- state : {
31
- value : 'disconnected' ,
32
- message : 'the worker state is incorrect'
33
- } ,
34
- exitedAfter : {
35
- value : false ,
36
- message : 'the .exitedAfterDisconnect flag is incorrect'
37
- } ,
38
- died : {
39
- value : true ,
40
- message : 'the worker is still running'
41
- } ,
42
- exitCode : {
43
- value : null ,
44
- message : 'the worker exited w/ incorrect exitCode'
45
- } ,
46
- signalCode : {
47
- value : KILL_SIGNAL ,
48
- message : 'the worker exited w/ incorrect signalCode'
49
- } ,
50
- numberOfWorkers : {
51
- value : 0 ,
52
- message : 'the number of workers running is wrong'
53
- } ,
54
- } ;
55
- const results = {
56
- emitDisconnect : 0 ,
57
- emitExit : 0
58
- } ;
59
21
60
22
// Start worker
61
23
const worker = cluster . fork ( ) ;
@@ -67,30 +29,21 @@ if (cluster.isWorker) {
67
29
68
30
// Check worker events and properties
69
31
worker . on ( 'disconnect' , common . mustCall ( ( ) => {
70
- results . emitDisconnect += 1 ;
71
- results . exitedAfter = worker . exitedAfterDisconnect ;
72
- results . state = worker . state ;
73
- } ) ) ;
32
+ assert . strictEqual ( worker . exitedAfterDisconnect , false ) ;
33
+ assert . strictEqual ( worker . state , 'disconnected' ) ;
34
+ } , 1 ) ) ;
74
35
75
36
// Check that the worker died
76
37
worker . once ( 'exit' , common . mustCall ( ( exitCode , signalCode ) => {
77
- // Setting the results
78
- results . exitCode = exitCode ;
79
- results . signalCode = signalCode ;
80
- results . emitExit += 1 ;
81
- results . died = ! common . isAlive ( worker . process . pid ) ;
82
- results . numberOfWorkers = Object . keys ( cluster . workers ) . length ;
83
- } ) ) ;
38
+ const isWorkerProcessStillAlive = common . isAlive ( worker . process . pid ) ;
39
+ const numOfRunningWorkers = Object . keys ( cluster . workers ) . length ;
84
40
85
- cluster . on ( 'exit' , common . mustCall ( ( ) => {
86
- // Checking if the results are as expected
87
- for ( const [ key , expected ] of Object . entries ( expectedResults ) ) {
88
- const actual = results [ key ] ;
41
+ assert . strictEqual ( exitCode , null ) ;
42
+ assert . strictEqual ( signalCode , KILL_SIGNAL ) ;
43
+ assert . strictEqual ( isWorkerProcessStillAlive , false ) ;
44
+ assert . strictEqual ( numOfRunningWorkers , 0 ) ;
45
+ } , 1 ) ) ;
89
46
90
- assert . strictEqual (
91
- actual , expected . value ,
92
- `${ expected . message } [expected: ${ expected . value } / actual: ${ actual } ]`
93
- ) ;
94
- }
95
- } ) ) ;
47
+ // Check if the cluster was killed as well
48
+ cluster . on ( 'exit' , common . mustCall ( ( ) => { } , 1 ) ) ;
96
49
}
0 commit comments