@@ -82,6 +82,28 @@ describe('test/index.test.ts', () => {
8282 // no exit event on coverage mode
8383 // child.expect('stdout', /worker \d+ died, code 0, signal null/);
8484 } ) ;
85+
86+ it ( 'should always listen sigterm work' , async ( ) => {
87+ const startFile = path . join ( fixtures , 'cluster.cjs' ) ;
88+ const child : any = coffee . fork ( startFile , [ ] , {
89+ env : {
90+ ...process . env ,
91+ ALWAYS_ON_SIGTERM : 'Y' ,
92+ } ,
93+ } )
94+ . debug ( ) ;
95+ await sleep ( waitStart ) ;
96+ child . proc . kill ( 'SIGTERM' ) ;
97+ await sleep ( 2200 ) ;
98+ if ( process . platform !== 'win32' ) {
99+ // windows can't handle SIGTERM signal
100+ child . expect ( 'stdout' , / \[ a p p - w o r k e r - \d \] r e c e i v e s i g n a l S I G T E R M , e x i t i n g w i t h c o d e : 0 / ) ;
101+ child . expect ( 'stdout' , / \[ a p p - w o r k e r - \d \] r e c e i v e s i g n a l S I G T E R M a g a i n , w a i t i n g f o r e x i t / ) ;
102+ child . expect ( 'stdout' , / e x i t a f t e r 1 0 0 0 m s / ) ;
103+ }
104+ child . expect ( 'stdout' , / \[ a p p - w o r k e r - 1 \] e x i t w i t h c o d e : 0 / ) ;
105+ child . expect ( 'stdout' , / \[ a p p - w o r k e r - 2 \] e x i t w i t h c o d e : 0 / ) ;
106+ } ) ;
85107 } ) ;
86108
87109 describe ( 'child_process.fork' , ( ) => {
@@ -101,6 +123,28 @@ describe('test/index.test.ts', () => {
101123 child . expect ( 'stderr' , / \[ t e s t - c h i l d \] e x i t w i t h c o d e : 1 1 0 / ) ;
102124 }
103125 } ) ;
126+
127+ it ( 'should always listen sigterm work' , async ( ) => {
128+ const startFile = path . join ( fixtures , 'master-sigterm.cjs' ) ;
129+ const child : any = coffee . fork ( startFile , [ ] , {
130+ env : {
131+ ...process . env ,
132+ ALWAYS_ON_SIGTERM : 'Y' ,
133+ } ,
134+ } )
135+ . debug ( ) ;
136+ await sleep ( waitStart ) ;
137+ // the worker exit by graceful-process
138+ child . proc . kill ( 'SIGTERM' ) ;
139+ await sleep ( 2000 ) ;
140+ if ( process . platform !== 'win32' ) {
141+ // windows can't handle SIGTERM signal
142+ child . expect ( 'stdout' , / \[ t e s t - c h i l d \] r e c e i v e s i g n a l S I G T E R M , e x i t i n g w i t h c o d e : 0 / ) ;
143+ child . expect ( 'stdout' , / \[ t e s t - c h i l d \] r e c e i v e s i g n a l S I G T E R M a g a i n , w a i t i n g f o r e x i t / ) ;
144+ child . expect ( 'stdout' , / e x i t a f t e r 1 0 0 0 m s / ) ;
145+ child . expect ( 'stdout' , / \[ t e s t - c h i l d \] e x i t w i t h c o d e : 0 / ) ;
146+ }
147+ } ) ;
104148 } ) ;
105149
106150 describe . skip ( 'child_process.spawn' , ( ) => {
0 commit comments