Skip to content

Commit

Permalink
test: refactor test-https-agent-additional-options
Browse files Browse the repository at this point in the history
Move callback to location where it is less confusing.

PR-URL: #27830
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Trott authored and targos committed May 28, 2019
1 parent 17abc8c commit a4c1fd5
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions test/parallel/test-https-agent-additional-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,12 @@ const updatedValues = new Map([
function variations(iter, port, cb) {
const { done, value } = iter.next();
if (done) {
return common.mustCall(cb);
} else {
const [key, val] = value;
return common.mustCall((res) => {
res.resume();
https.globalAgent.once('free', common.mustCall(() => {
https.get(
Object.assign({}, getBaseOptions(port), { [key]: val }),
variations(iter, port, cb)
);
}));
});
}
}

server.listen(0, common.mustCall(() => {
const port = server.address().port;
const globalAgent = https.globalAgent;
globalAgent.keepAlive = true;
https.get(getBaseOptions(port), variations(
updatedValues.entries(),
port,
common.mustCall((res) => {
res.resume();
globalAgent.once('free', common.mustCall(() => {
// Verify that different keep-alived connections are created
// for the base call and each variation
const keys = Object.keys(globalAgent.freeSockets);
const keys = Object.keys(https.globalAgent.freeSockets);
assert.strictEqual(keys.length, 1 + updatedValues.size);
let i = 1;
for (const [, value] of updatedValues) {
Expand All @@ -80,9 +58,26 @@ server.listen(0, common.mustCall(() => {
);
i++;
}
globalAgent.destroy();
https.globalAgent.destroy();
server.close();
}));
})
));
});
} else {
const [key, val] = value;
return common.mustCall((res) => {
res.resume();
https.globalAgent.once('free', common.mustCall(() => {
https.get(
Object.assign({}, getBaseOptions(port), { [key]: val }),
variations(iter, port, cb)
);
}));
});
}
}

server.listen(0, common.mustCall(() => {
const port = server.address().port;
https.globalAgent.keepAlive = true;
https.get(getBaseOptions(port), variations(updatedValues.entries(), port));
}));

0 comments on commit a4c1fd5

Please sign in to comment.