-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
ec53a15
to
71f0b14
Compare
71f0b14
to
cfaf6bf
Compare
get(`http://127.0.0.1:${internal.address().port}`, common.mustCall((inner) => { | ||
res.on('close', common.mustCall(() => { | ||
assert.strictEqual(res.writable, true); | ||
})); | ||
inner.pipe(res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to call external.abort()
and internalRes.end('Hello World\n');
here or does this invalidate the test?
This would remove the setTimeout
dependency.
@lpinca the problem is that this test keeps failing only on Centos and I do not know why :( |
Yes that's weird, it looks like |
While you're here, could you move the stuff from |
cfaf6bf
to
8772804
Compare
8772804
to
a2ba6b8
Compare
a2ba6b8
to
a4c7be8
Compare
a4c7be8
to
9b36dfa
Compare
9b36dfa
to
643f8a8
Compare
643f8a8
to
830dda8
Compare
@mcollina we could also mark the test as being flaky on centos? |
830dda8
to
d349345
Compare
// everywhere else, 'close' is emitted | ||
res.on('close', () => { | ||
assert.strictEqual(res.writable, true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will test less than before, since the mustCall
is not in place anymore. It might be worth to check that either finish
or close
will be called at least once? And I am somewhat surprised that our events are platform dependent. Would you be so kind and add a comment why that is the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea on why it's the case, that's the major problem of this PR.
I'll see if I can get another solution as well.
I'll add another check that verifies that at least one of them is called.
d349345
to
717a67a
Compare
061f7a9
to
f2061d8
Compare
CI: https://ci.nodejs.org/job/node-test-pull-request/10273/ This should be green, and it can land as it finshes. @jasnell @lpinca @cjihrig can you review it again so we can land? |
@@ -1,4 +1,4 @@ | |||
'use strict'; | |||
use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing '
res.on('finish', console.log.bind(console, 'finish emitted')); | ||
res.on('close', console.log.bind(console, 'close emitted')); | ||
|
||
// on CentOS, 'finish' is emitted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd point out that this only happens on CentOS 5.
})); | ||
}) | ||
|
||
res.on('finish', console.log.bind(console, 'finish emitted')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these are only for debugging. Do we want to keep them?
f2061d8
to
7d6a0aa
Compare
@lpinca thanks, updated! |
assert.strictEqual(res.writable, true); | ||
})); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.
// on CentOS 5, 'finish' is emitted | ||
res.on('finish', listener); | ||
// everywhere else, 'close' is emitted | ||
res.on('close', listener) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
res.writeHead(200); | ||
setImmediate(common.mustCall(() => { | ||
external.abort(); | ||
external.socket.on('close', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this isn't needed after all.
// 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(() => { |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
7d6a0aa
to
adf649a
Compare
adf649a
to
dfd4c63
Compare
Still LGTM. |
Landed as 1fe9b53 |
Ref: nodejs#15404 Fixes: nodejs#15505 PR-URL: nodejs#15520 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Ref: nodejs/node#15404 Fixes: nodejs/node#15505 PR-URL: nodejs/node#15520 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Ref: #15404
Fixes: #15505
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test, http