@@ -14,7 +14,8 @@ describe('suspend before stop', () => {
14
14
it ( 'master calls suspend and waits for it to finish before stop' , async ( ) => {
15
15
await instance . sendWaitTimeout ( 'register suspend 100' , 10 ) ;
16
16
await instance . sendWaitAnswer ( 'soft-restart' , 'restarted' ) ;
17
- const expected = `Waiting 100ms in suspend function
17
+ const expected = `Got ready
18
+ Waiting 100ms in suspend function
18
19
Finished waiting 100ms in suspend function
19
20
Got disconnect
20
21
` ;
@@ -23,15 +24,16 @@ Got disconnect
23
24
24
25
it ( 'master disconnected worker if no suspend function was registered' , async ( ) => {
25
26
await instance . sendWaitAnswer ( 'soft-restart' , 'restarted' ) ;
26
- const expected = 'Got disconnect\n' ;
27
+ const expected = 'Got ready\nGot disconnect\n' ;
27
28
assert . equal ( instance . output ( ) , expected ) ;
28
29
} ) ;
29
30
30
31
it ( 'worker waits for all registered suspend functions' , async ( ) => {
31
32
await instance . sendWaitTimeout ( 'register suspend 100' , 10 ) ;
32
33
await instance . sendWaitTimeout ( 'register suspend 200' , 10 ) ;
33
34
await instance . sendWaitAnswer ( 'soft-restart' , 'restarted' ) ;
34
- const expected = `Waiting 100ms in suspend function
35
+ const expected = `Got ready
36
+ Waiting 100ms in suspend function
35
37
Waiting 200ms in suspend function
36
38
Finished waiting 100ms in suspend function
37
39
Finished waiting 200ms in suspend function
@@ -41,9 +43,26 @@ Got disconnect
41
43
} ) ;
42
44
43
45
it ( 'master kills worker if suspend did not finish in stopTimeout' , async ( ) => {
44
- await instance . sendWaitTimeout ( 'register suspend 100000 ' , 10 ) ;
46
+ await instance . sendWaitTimeout ( 'register suspend 3000 ' , 10 ) ;
45
47
await instance . sendWaitAnswer ( 'soft-restart' , 'restarted' ) ;
46
- const expected = 'Waiting 100000ms in suspend function\n' ;
48
+ const expected = 'Got ready\nWaiting 3000ms in suspend function\n' ;
49
+ assert . equal ( instance . output ( ) , expected ) ;
50
+ } ) ;
51
+
52
+ it ( 'master does not disconnect already killed worker' , async function ( ) {
53
+ // eslint-disable-next-line no-invalid-this
54
+ this . timeout ( 15000 ) ;
55
+
56
+ await instance . sendWaitTimeout ( 'register suspend 3000' , 10 ) ;
57
+ await instance . sendWaitAnswer ( 'soft-restart' , 'restarted' ) ;
58
+ // No "Got disconnect" is expected
59
+ const expected = `Got ready
60
+ Waiting 3000ms in suspend function
61
+ Got ready
62
+ ` ;
63
+
64
+ await new Promise ( resolve => setTimeout ( resolve , 10000 ) ) ;
65
+
47
66
assert . equal ( instance . output ( ) , expected ) ;
48
67
} ) ;
49
68
@@ -53,7 +72,8 @@ Got disconnect
53
72
const exitCode = await instance . sendWaitExit ( 'shutdown' ) ;
54
73
55
74
// Keep those two 'shutting down' to make sure master process got our message and called 'shutdown' twice
56
- const expected = `Shutting down
75
+ const expected = `Got ready
76
+ Shutting down
57
77
Shutting down
58
78
Waiting 100ms in suspend function
59
79
Finished waiting 100ms in suspend function
0 commit comments