From a4c1fd5ffc4da36d9364c9cadd3b2b88089dd8e8 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 21 May 2019 15:27:32 -0700 Subject: [PATCH] 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 Reviewed-By: Luigi Pinca --- .../test-https-agent-additional-options.js | 47 +++++++++---------- 1 file 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 2a5bde72a09621..42d913c2ea264a 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)); }));