summaryrefslogtreecommitdiff
path: root/test/parallel/test-https-agent-additional-options.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-05-21 16:36:36 -0700
committerRich Trott <rtrott@gmail.com>2019-05-24 19:26:46 -0700
commit0d2830041a399d5d56f7e0780c982a80570bdde2 (patch)
tree4c01963bb87859c8109e790d61d27f61793edd60 /test/parallel/test-https-agent-additional-options.js
parent0fa5c9f256210d858862e62f63754f216a94e1e9 (diff)
downloadandroid-node-v8-0d2830041a399d5d56f7e0780c982a80570bdde2.tar.gz
android-node-v8-0d2830041a399d5d56f7e0780c982a80570bdde2.tar.bz2
android-node-v8-0d2830041a399d5d56f7e0780c982a80570bdde2.zip
test: fix test-https-agent-additional-options
test-https-agent-additional-options can occasionally fail if a socket closes before the checks near the end of the test. Modify the test to check the freeSockets pool after each request. PR-URL: https://github.com/nodejs/node/pull/27830 Fixes: https://github.com/nodejs/node/issues/24449 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.js58
1 files changed, 26 insertions, 32 deletions
diff --git a/test/parallel/test-https-agent-additional-options.js b/test/parallel/test-https-agent-additional-options.js
index 42d913c2ea..99fcd0126a 100644
--- a/test/parallel/test-https-agent-additional-options.js
+++ b/test/parallel/test-https-agent-additional-options.js
@@ -39,41 +39,35 @@ const updatedValues = new Map([
['sessionIdContext', 'sessionIdContext'],
]);
+let value;
function variations(iter, port, cb) {
- const { done, value } = iter.next();
- if (done) {
- return common.mustCall((res) => {
- res.resume();
- https.globalAgent.once('free', common.mustCall(() => {
- // Verify that different keep-alived connections are created
- // for the base call and each variation
- const keys = Object.keys(https.globalAgent.freeSockets);
- assert.strictEqual(keys.length, 1 + updatedValues.size);
- let i = 1;
- for (const [, value] of updatedValues) {
- assert.ok(
- keys[i].startsWith(value.toString() + ':') ||
- keys[i].endsWith(':' + value.toString()) ||
- keys[i].includes(':' + value.toString() + ':')
- );
- i++;
- }
+ return common.mustCall((res) => {
+ res.resume();
+ https.globalAgent.once('free', common.mustCall(() => {
+ // Verify that the most recent connection is in the freeSockets pool.
+ const keys = Object.keys(https.globalAgent.freeSockets);
+ if (value) {
+ assert.ok(
+ keys.some((val) => val.startsWith(value.toString() + ':') ||
+ val.endsWith(':' + value.toString()) ||
+ val.includes(':' + value.toString() + ':')),
+ `missing value: ${value.toString()} in ${keys}`
+ );
+ }
+ const next = iter.next();
+
+ if (next.done) {
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)
- );
- }));
- });
- }
+ } else {
+ // Save `value` for check the next time.
+ value = next.value.val;
+ const [key, val] = next.value;
+ https.get(Object.assign({}, getBaseOptions(port), { [key]: val }),
+ variations(iter, port, cb));
+ }
+ }));
+ });
}
server.listen(0, common.mustCall(() => {