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.
  • Loading branch information
Trott committed May 22, 2019
1 parent 9181f38 commit 212ecda
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 212ecda

Please sign in to comment.