Skip to content

Commit a4c1fd5

Browse files
Trotttargos
authored andcommitted
test: refactor test-https-agent-additional-options
Move callback to location where it is less confusing. PR-URL: #27830 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 17abc8c commit a4c1fd5

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

test/parallel/test-https-agent-additional-options.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,12 @@ const updatedValues = new Map([
4242
function variations(iter, port, cb) {
4343
const { done, value } = iter.next();
4444
if (done) {
45-
return common.mustCall(cb);
46-
} else {
47-
const [key, val] = value;
4845
return common.mustCall((res) => {
4946
res.resume();
5047
https.globalAgent.once('free', common.mustCall(() => {
51-
https.get(
52-
Object.assign({}, getBaseOptions(port), { [key]: val }),
53-
variations(iter, port, cb)
54-
);
55-
}));
56-
});
57-
}
58-
}
59-
60-
server.listen(0, common.mustCall(() => {
61-
const port = server.address().port;
62-
const globalAgent = https.globalAgent;
63-
globalAgent.keepAlive = true;
64-
https.get(getBaseOptions(port), variations(
65-
updatedValues.entries(),
66-
port,
67-
common.mustCall((res) => {
68-
res.resume();
69-
globalAgent.once('free', common.mustCall(() => {
7048
// Verify that different keep-alived connections are created
7149
// for the base call and each variation
72-
const keys = Object.keys(globalAgent.freeSockets);
50+
const keys = Object.keys(https.globalAgent.freeSockets);
7351
assert.strictEqual(keys.length, 1 + updatedValues.size);
7452
let i = 1;
7553
for (const [, value] of updatedValues) {
@@ -80,9 +58,26 @@ server.listen(0, common.mustCall(() => {
8058
);
8159
i++;
8260
}
83-
globalAgent.destroy();
61+
https.globalAgent.destroy();
8462
server.close();
8563
}));
86-
})
87-
));
64+
});
65+
} else {
66+
const [key, val] = value;
67+
return common.mustCall((res) => {
68+
res.resume();
69+
https.globalAgent.once('free', common.mustCall(() => {
70+
https.get(
71+
Object.assign({}, getBaseOptions(port), { [key]: val }),
72+
variations(iter, port, cb)
73+
);
74+
}));
75+
});
76+
}
77+
}
78+
79+
server.listen(0, common.mustCall(() => {
80+
const port = server.address().port;
81+
https.globalAgent.keepAlive = true;
82+
https.get(getBaseOptions(port), variations(updatedValues.entries(), port));
8883
}));

0 commit comments

Comments
 (0)