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

Conversation

mcollina
Copy link
Member

Ref: #15404
Fixes: #15505

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test, http

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Sep 21, 2017
@mcollina
Copy link
Member Author

@mscdex mscdex added the http Issues or PRs related to the http subsystem. label Sep 21, 2017
@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

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);
Copy link
Member

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.

@mcollina
Copy link
Member Author

@lpinca the problem is that this test keeps failing only on Centos and I do not know why :(

@lpinca
Copy link
Member

lpinca commented Sep 21, 2017

Yes that's weird, it looks like res.on('close', ...) is not emitted but I don't know why.

@cjihrig
Copy link
Contributor

cjihrig commented Sep 21, 2017

While you're here, could you move the stuff from // Proxy server until the end of the file into the internal server's listen() callback?

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

@BridgeAR
Copy link
Member

@mcollina we could also mark the test as being flaky on centos?

@mcollina
Copy link
Member Author

// everywhere else, 'close' is emitted
res.on('close', () => {
assert.strictEqual(res.writable, true);
});
Copy link
Member

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?

Copy link
Member Author

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.

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

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';
Copy link
Member

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
Copy link
Member

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'));
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 these are only for debugging. Do we want to keep them?

@mcollina
Copy link
Member Author

assert.strictEqual(res.writable, true);
}));
})
Copy link
Member

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)
Copy link
Member

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', () => {
Copy link
Contributor

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(() => {
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.

@mcollina
Copy link
Member Author

@mcollina
Copy link
Member Author

@lpinca
Copy link
Member

lpinca commented Sep 27, 2017

Still LGTM.

@mcollina
Copy link
Member Author

Landed as 1fe9b53

@mcollina mcollina closed this Sep 27, 2017
@mcollina mcollina deleted the fix-flaky-http-test branch September 27, 2017 13:09
mcollina added a commit that referenced this pull request Sep 27, 2017
Ref: #15404
Fixes: #15505
PR-URL: #15520
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit to MylesBorins/node that referenced this pull request Sep 28, 2017
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>
MylesBorins pushed a commit that referenced this pull request Sep 29, 2017
Ref: #15404
Fixes: #15505
PR-URL: #15520
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott Trott mentioned this pull request Sep 30, 2017
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 30, 2017
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>
@MylesBorins MylesBorins mentioned this pull request Oct 3, 2017
MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
Ref: #15404
Fixes: #15505
PR-URL: #15520
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants