Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix abort test timing to be consistent from node v12 through v16 #4239

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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