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: refactoring test with common.mustCall #12702

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions test/parallel/test-https-simple.js
Expand Up @@ -55,28 +55,31 @@ const serverCallback = common.mustCall(function(req, res) {

const server = https.createServer(options, serverCallback);

server.listen(0, function() {
server.listen(0, common.mustCall(() => {
// Do a request ignoring the unauthorized server certs
const port = server.address().port;

const noCertCheckOptions = {
hostname: '127.0.0.1',
port: this.address().port,
port: port,
path: '/',
method: 'GET',
rejectUnauthorized: false
};

noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions);

const req = https.request(noCertCheckOptions, function(res) {
const req = https.request(noCertCheckOptions, common.mustCall((res) => {
let responseBody = '';
res.on('data', function(d) {
responseBody = responseBody + d;
});

res.on('end', function() {
res.on('end', 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.

The enclosing https.request() and server.listen() callbacks need to have common.mustCall() too, or there is no guarantee that this will execute.

assert.strictEqual(responseBody, body);
testSucceeded();
});
});
}));
}));
req.end();

req.on('error', function(e) {
Expand All @@ -86,7 +89,7 @@ server.listen(0, function() {
// Do a request that throws error due to the invalid server certs
const checkCertOptions = {
hostname: '127.0.0.1',
port: this.address().port,
port: port,
path: '/',
method: 'GET'
};
Expand All @@ -102,11 +105,11 @@ server.listen(0, function() {
});
checkCertReq.end();

checkCertReq.on('error', function(e) {
checkCertReq.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
testSucceeded();
});
});
}));
}));

process.on('exit', function() {
assert.strictEqual(successful, tests);
Expand Down