summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/connection-pool/resources/network-partition-key.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/fetch/connection-pool/resources/network-partition-key.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/fetch/connection-pool/resources/network-partition-key.js')
-rw-r--r--testing/web-platform/tests/fetch/connection-pool/resources/network-partition-key.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/connection-pool/resources/network-partition-key.js b/testing/web-platform/tests/fetch/connection-pool/resources/network-partition-key.js
new file mode 100644
index 0000000000..bd66109380
--- /dev/null
+++ b/testing/web-platform/tests/fetch/connection-pool/resources/network-partition-key.js
@@ -0,0 +1,47 @@
+// Runs multiple fetches that validate connections see only a single partition_id.
+// Requests are run in parallel so that they use multiple connections to maximize the
+// chance of exercising all matching connections in the connection pool. Only returns
+// once all requests have completed to make cleaning up server state non-racy.
+function check_partition_ids(location) {
+ const NUM_FETCHES = 20;
+
+ var base_url = 'SUBRESOURCE_PREFIX:&dispatch=check_partition';
+
+ // Not a perfect parse of the query string, but good enough for this test.
+ var include_credentials = base_url.search('include_credentials=true') != -1;
+ var exclude_credentials = base_url.search('include_credentials=false') != -1;
+ if (include_credentials != !exclude_credentials)
+ throw new Exception('Credentials mode not specified');
+
+
+ // Run NUM_FETCHES in parallel.
+ var fetches = [];
+ for (i = 0; i < NUM_FETCHES; ++i) {
+ var fetch_params = {
+ credentials: 'omit',
+ mode: 'cors',
+ headers: {
+ 'Header-To-Force-CORS': 'cors'
+ },
+ };
+
+ // Use a unique URL for each request, in case the caching layer serializes multiple
+ // requests for the same URL.
+ var url = `${base_url}&${token()}`;
+
+ fetches.push(fetch(url, fetch_params).then(
+ function (response) {
+ return response.text().then(function(text) {
+ assert_equals(text, 'ok', `Socket unexpectedly reused`);
+ });
+ }));
+ }
+
+ // Wait for all promises to complete.
+ return Promise.allSettled(fetches).then(function (results) {
+ results.forEach(function (result) {
+ if (result.status != 'fulfilled')
+ throw result.reason;
+ });
+ });
+}