summaryrefslogtreecommitdiff
path: root/test/parallel/test-https-agent-additional-options.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-05-21 15:27:32 -0700
committerRich Trott <rtrott@gmail.com>2019-05-24 19:26:43 -0700
commit0fa5c9f256210d858862e62f63754f216a94e1e9 (patch)
tree074a0840051165bbd37100ccfdd854b34295c892 /test/parallel/test-https-agent-additional-options.js
parentd03cff7620f0a62433f36abc252532ab0a79a56c (diff)
downloadandroid-node-v8-0fa5c9f256210d858862e62f63754f216a94e1e9.tar.gz
android-node-v8-0fa5c9f256210d858862e62f63754f216a94e1e9.tar.bz2
android-node-v8-0fa5c9f256210d858862e62f63754f216a94e1e9.zip
test: refactor test-https-agent-additional-options
Move callback to location where it is less confusing. PR-URL: https://github.com/nodejs/node/pull/27830 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/parallel/test-https-agent-additional-options.js')
-rw-r--r--test/parallel/test-https-agent-additional-options.js47
1 files changed, 21 insertions, 26 deletions
diff --git a/test/parallel/test-https-agent-additional-options.js b/test/parallel/test-https-agent-additional-options.js
index 2a5bde72a0..42d913c2ea 100644
--- a/test/parallel/test-https-agent-additional-options.js
+++ b/test/parallel/test-https-agent-additional-options.js
@@ -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) {
@@ -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));
}));