@@ -32,6 +32,7 @@ const a: any = require('awaiting');
32
32
const request : any = require ( 'requisition' ) ;
33
33
import fs from 'fs' ;
34
34
import { Stopper } from '../../../plugin/drainHttpServer/stoppable' ;
35
+ import child from 'child_process' ;
35
36
import path from 'path' ;
36
37
import type { AddressInfo } from 'net' ;
37
38
import { describe , it , expect , afterEach , beforeEach } from '@jest/globals' ;
@@ -135,9 +136,7 @@ Object.keys(schemes).forEach((schemeName) => {
135
136
) ,
136
137
) ;
137
138
expect ( err . code ) . toMatch ( / E C O N N R E F U S E D / ) ;
138
-
139
- const isNode20 = ! ! process . version . match ( / ^ v 2 0 \. / ) ;
140
- expect ( closed ) . toBe ( isNode20 ? 1 : 0 ) ;
139
+ expect ( closed ) . toBe ( 0 ) ;
141
140
} ) ;
142
141
} ) ;
143
142
@@ -302,21 +301,12 @@ Object.keys(schemes).forEach((schemeName) => {
302
301
303
302
if ( schemeName === 'http' ) {
304
303
it ( 'with in-flights finishing before grace period ends' , async ( ) => {
305
- let stopper : Stopper ;
306
- const killServerBarrier = resolvable ( ) ;
307
- const server = http . createServer ( async ( _ , res ) => {
308
- res . writeHead ( 200 ) ;
309
- res . write ( 'hello' ) ;
310
-
311
- await killServerBarrier ;
312
- res . end ( 'world' ) ;
313
- await stopper . stop ( ) ;
314
- } ) ;
315
- stopper = new Stopper ( server ) ;
316
- server . listen ( 0 ) ;
317
- const p = port ( server ) ;
318
-
319
- const res = await request ( `${ schemeName } ://localhost:${ p } /` ) . agent (
304
+ const file = path . join ( __dirname , 'stoppable' , 'server.js' ) ;
305
+ const server = child . spawn ( 'node' , [ file ] ) ;
306
+ const [ data ] = await a . event ( server . stdout , 'data' ) ;
307
+ const port = + data . toString ( ) ;
308
+ expect ( typeof port ) . toBe ( 'number' ) ;
309
+ const res = await request ( `${ schemeName } ://localhost:${ port } /` ) . agent (
320
310
scheme . agent ( { keepAlive : true } ) ,
321
311
) ;
322
312
let gotBody = false ;
@@ -330,13 +320,13 @@ Object.keys(schemes).forEach((schemeName) => {
330
320
expect ( gotBody ) . toBe ( false ) ;
331
321
332
322
// Tell the server that its request should finish.
333
- killServerBarrier . resolve ( ) ;
323
+ server . kill ( 'SIGUSR1' ) ;
334
324
335
325
const body = await bodyPromise ;
336
326
expect ( gotBody ) . toBe ( true ) ;
337
327
expect ( body ) . toBe ( 'helloworld' ) ;
338
328
339
- // Wait for server to close .
329
+ // Wait for subprocess to go away .
340
330
await a . event ( server , 'close' ) ;
341
331
} ) ;
342
332
}
0 commit comments