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: refactor parallel/test-tls-delayed-attach #19421

Closed
Closed
Changes from 1 commit
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
22 changes: 12 additions & 10 deletions test/parallel/test-tls-delayed-attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

// Checks tls delay
Copy link
Member

Choose a reason for hiding this comment

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

Can we get a more descriptive comment here? This doesn't add any information that isn't in the file name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

more description added


const fixtures = require('../common/fixtures');
const assert = require('assert');
const tls = require('tls');
Expand All @@ -37,30 +39,30 @@ const options = {
cert: fixtures.readKey('agent1-cert.pem')
};

const server = net.createServer(function(c) {
const server = net.createServer(common.mustCall((c) => {
setTimeout(function() {
const s = new tls.TLSSocket(c, {
isServer: true,
secureContext: tls.createSecureContext(options)
});

s.on('data', function(chunk) {
s.on('data', common.mustCall((chunk) => {
Copy link
Member

@Trott Trott Mar 18, 2018

Choose a reason for hiding this comment

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

This should not be wrapped in common.mustCall(), I don't think. It is theoretically possible for the data event to be emitted more than once (although perhaps not without the underlying implementation changing).

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps common.mustCallAtLeast()?

Copy link
Member

@Trott Trott Mar 18, 2018

Choose a reason for hiding this comment

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

I wouldn't use common.mustCallAtLeast() here because it will never result in a failure if the callback never runs, because the process.on('exit') will fail first. So adding common.mustCallAtLeast() will only add cognitive overhead when trying to understand the test.

Copy link
Member

Choose a reason for hiding this comment

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

Should the on('exit') callback be common.mustCall() then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so should I removecommon.mustCall ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@richardlau on('exit') its giving error

Copy link
Member

Choose a reason for hiding this comment

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

Should the on('exit') callback be common.mustCall() then?

No, because common.mustCall() does it's checks via .on('exit') so you can't use common.mustCall() on exit handlers. I think the thing to do is not rely on common.mustCall() for this. (I do think we tend to overuse it and should only use it where needed, but I may be in the minority on that.)

Copy link
Member

Choose a reason for hiding this comment

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

so should I removecommon.mustCall ?

IMO, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes made :)
thank you for feedback

received += chunk;
});
}));

s.on('end', function() {
s.on('end', common.mustCall(() => {
server.close();
s.destroy();
});
}));
}, 200);
}).listen(0, function() {
const c = tls.connect(this.address().port, {
})).listen(0, common.mustCall(() => {
const c = tls.connect(server.address().port, {
rejectUnauthorized: false
}, function() {
}, () => {
c.end(sent);
});
});
}));

process.on('exit', function() {
process.on('exit', () => {
assert.strictEqual(received, sent);
});