Skip to content

Commit

Permalink
Fix abort test timing to be consistent from node v12 through v16 (#4239)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy authored Mar 20, 2021
1 parent 0e71bf4 commit e95683a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ describe('Request', () => {
expect(info.remoteAddress).to.exist();
});

it('handles aborted requests (pre response)', { retry: true }, async () => {
it('handles aborted requests (before response)', { retry: true }, async (flags) => {

const server = Hapi.server();
server.route({
Expand All @@ -533,15 +533,26 @@ describe('Request', () => {

server.ext('onRequest', onRequest);

const onPreHandler = (request, h) => {
let firstRequest = true;
const onPreHandler = async (request, h) => {

if (firstRequest) {
client.destroy();
firstRequest = false;
}
else {
// To avoid timing differences between node versions, ensure that
// the second and third requests always experience the disconnect
await team.work;
}

client.destroy();
return h.continue;
};

server.ext('onPreHandler', onPreHandler);

await server.start();
flags.onCleanup = () => server.stop();

const client = Net.connect(server.info.port, () => {

Expand All @@ -553,7 +564,7 @@ describe('Request', () => {
await team.work;
await server.stop();

expect(codes).to.equal([204, 204, 499]);
expect(codes).to.equal([204, 499, 499]);
});

it('returns empty params array when none present', async () => {
Expand Down

0 comments on commit e95683a

Please sign in to comment.