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

test: defer abort with setTimeout #15520

Closed
wants to merge 1 commit into from
Closed
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
39 changes: 23 additions & 16 deletions test/parallel/test-http-writable-true-after-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,36 @@ const { get, createServer } = require('http');
// res.writable should not be set to false after it has finished sending
// Ref: https://github.com/nodejs/node/issues/15029

let internal;
let external;

// Http server
const internal = createServer((req, res) => {
res.writeHead(200);
setImmediate(common.mustCall(() => {
external.abort();
res.end('Hello World\n');
}));
}).listen(0);

// Proxy server
const server = createServer(common.mustCall((req, res) => {
get(`http://127.0.0.1:${internal.address().port}`, common.mustCall((inner) => {
res.on('close', common.mustCall(() => {
const listener = common.mustCall(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this called more than once on any platforms? Removing the listeners kind of defeats the purpose of wrapping it in common.mustCall().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the point is to ensure that the listener is actually called.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but common.mustCall() also enforces the number of times the function is called. Removing the listeners means we lose that checking.

Copy link
Member

@lpinca lpinca Sep 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either 'close' or 'finish' should be emitted so it doesn't matter as long as at least one is emitted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I asked:

Is this called more than once on any platforms?

We shouldn't remove the listeners unless we really need to.

assert.strictEqual(res.writable, true);
}));
});

// on CentOS 5, 'finish' is emitted
res.on('finish', listener);
// everywhere else, 'close' is emitted
res.on('close', listener);

inner.pipe(res);
}));
})).listen(0, () => {
external = get(`http://127.0.0.1:${server.address().port}`);
external.on('error', common.mustCall((err) => {
server.close();
internal.close();
}));
// Http server
internal = createServer((req, res) => {
res.writeHead(200);
setImmediate(common.mustCall(() => {
external.abort();
res.end('Hello World\n');
}));
}).listen(0, () => {
external = get(`http://127.0.0.1:${server.address().port}`);
external.on('error', common.mustCall((err) => {
server.close();
internal.close();
}));
});
});