@@ -19,6 +19,7 @@ const Hapi = require('..');
19
19
const Hoek = require ( '@hapi/hoek' ) ;
20
20
const Inert = require ( '@hapi/inert' ) ;
21
21
const Lab = require ( '@hapi/lab' ) ;
22
+ const Teamwork = require ( '@hapi/teamwork' ) ;
22
23
const Vision = require ( '@hapi/vision' ) ;
23
24
const Wreck = require ( '@hapi/wreck' ) ;
24
25
@@ -938,6 +939,26 @@ describe('Core', () => {
938
939
expect ( server . _core . started ) . to . equal ( false ) ;
939
940
} ) ;
940
941
942
+ it ( 'allows incoming requests during the stopping phase' , async ( ) => {
943
+
944
+ const team = new Teamwork . Team ( ) ;
945
+
946
+ const server = Hapi . server ( ) ;
947
+ server . route ( { method : 'GET' , path : '/' , handler : ( ) => 'ok' } ) ;
948
+ server . ext ( 'onPreStop' , ( ) => team . work ) ;
949
+
950
+ await server . start ( ) ;
951
+ const stop = server . stop ( ) ;
952
+ const { res, payload } = await Wreck . get ( `http://localhost:${ server . info . port } ` ) ;
953
+
954
+ team . attend ( ) ; // Allow server to finalize stop
955
+ await stop ;
956
+
957
+ expect ( res . headers . connection ) . to . equal ( 'close' ) ;
958
+ expect ( payload . toString ( ) ) . to . equal ( 'ok' ) ;
959
+ expect ( server . _core . started ) . to . equal ( false ) ;
960
+ } ) ;
961
+
941
962
it ( 'finishes in-progress requests and ends connection' , async ( ) => {
942
963
943
964
let stop ;
0 commit comments