You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @default Destroys any incoming requests without further processing (client receives `ECONNRESET`).
225
+
* Custom handler to override the response to incoming request during the gracefully shutdown period.
226
+
* NOTE: The handler is called before decorating (and authenticating) the request object. The `req` object might be much simpler than the usual Lifecycle method.
227
+
*/
228
+
stoppingHandler?: Lifecycle.Method;
229
+
222
230
/**
223
231
* @default none.
224
232
* Used to create an HTTPS connection. The tls object is passed unchanged to the node HTTPS server as described in the node HTTPS documentation.
// Stop the server while the request is in progress
641
+
awaitHoek.wait(1_000);
642
+
consttimer=newHoek.Bench();
643
+
awaitserver.stop({timeout: shutdownTimeout});
644
+
expect(timer.elapsed()).to.be.greaterThan(900);// if the test takes less than 1s, the server is not holding for the request to complete (or there's a shortcut in the testkit)
645
+
expect(timer.elapsed()).to.be.lessThan(1_500);// it should be done in less than 1.5s, given that the request takes 2s and 1s has already passed (with a given offset)
646
+
647
+
648
+
constres=awaitreq;
649
+
expect(res.statusCode).to.equal(200);
650
+
constbody=awaitWreck.read(res);
651
+
expect(body.toString()).to.equal('ok');
652
+
expect(res.headers.connection).to.equal('close');
653
+
awaitexpect(req).to.not.reject();
654
+
});
655
+
656
+
it('rejects incoming requests during the stopping phase',async()=>{
657
+
658
+
constshutdownTimeout=4_000;
659
+
constserver=Hapi.server();
660
+
server.route({
661
+
method: 'get',path: '/',handler: async(_,res)=>{
662
+
663
+
awaitHoek.wait(shutdownTimeout);
664
+
returnres.response('ok');
665
+
}
666
+
});
667
+
awaitserver.start();
668
+
669
+
consturl=`http://localhost:${server.info.port}/`;
670
+
671
+
// Just performing one request to hold the server from immediately stopping.
672
+
constfirstRequest=Wreck.request('GET',url);
673
+
674
+
// Stop the server while the request is in progress
0 commit comments