Skip to content

Commit

Permalink
Fix coverage
Browse files Browse the repository at this point in the history
This includes a fix to immediately destroy incoming requests when in the stopping phase.

Node 20+ implicitly does this, so a coverage exception is needed.
  • Loading branch information
kanongil authored and Marsup committed Jan 29, 2024
1 parent 7e7d5ea commit d59bdc6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .labrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const Somever = require('@hapi/somever');

module.exports = {
'coverage-predicates': {
allowsStoppedReq: Somever.match(process.version, '<=18'),
}
};
6 changes: 6 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ exports = module.exports = internals.Core = class {

return (req, res) => {

// $lab:coverage:off$ $not:allowsStoppedReq$
if (this.phase === 'stopping') {
return req.destroy();
}
// $lab:coverage:on$ $not:allowsStoppedReq$

// Create request

const request = Request.generate(this.root, req, res, options);
Expand Down
4 changes: 1 addition & 3 deletions lib/transmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ internals.end = function (env, event, err) {
env.team = null;

if (request.raw.res.writableEnded) {
if (!event) {
request.info.responded = Date.now();
}
request.info.responded = Date.now();

team.attend();
return;
Expand Down
4 changes: 3 additions & 1 deletion test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,13 @@ describe('Core', () => {
const { res, payload } = await first;
const stop = server.stop();

await expect(second).to.reject();
const err = await expect(second).to.reject(Error);
await stop;
await Hoek.wait(10);

expect(res.headers.connection).to.equal('keep-alive');
expect(payload.toString()).to.equal('ok');
expect(err.code).to.equal('ECONNRESET');
expect(server._core.started).to.equal(false);
});

Expand Down

0 comments on commit d59bdc6

Please sign in to comment.