tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_multipleOpensInParallel.js (2403B)


      1 /*
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 const { PrincipalUtils } = ChromeUtils.importESModule(
      7  "resource://testing-common/dom/quota/test/modules/PrincipalUtils.sys.mjs"
      8 );
      9 const { IndexedDBUtils } = ChromeUtils.importESModule(
     10  "resource://testing-common/dom/indexedDB/test/modules/IndexedDBUtils.sys.mjs"
     11 );
     12 
     13 /**
     14 * This is not a formal performance test — see the dedicated perf tests for
     15 * actual metrics.
     16 *
     17 * This test exists to:
     18 *   - Provide fast, local verification during development.
     19 *   - May detect early regressions in scheduling logic before perf test
     20 *     results are available.
     21 *
     22 * It simulates multiple concurrent open requests to the same database. Only
     23 * one should run at a time, and the rest should be scheduled efficiently.
     24 *
     25 * If scheduling or cleanup is slow, this test may fail due to timeout.
     26 *
     27 * Note: Not only the number of requests, but also the number of live (open)
     28 * databases may affect performance.
     29 *
     30 * Note: This test could theoretically be combined with its counterpart in a
     31 * single file with multiple tasks, but they are intentionally split to:
     32 *   - Avoid interference between test cases
     33 *   - Make it obvious which scenario timed out (serial vs. parallel)
     34 */
     35 
     36 /* exported testSteps */
     37 async function testSteps() {
     38  const principal = PrincipalUtils.createPrincipal("https://example.com");
     39  const name = "multipleOpensInParallel";
     40 
     41  info("Opening databases");
     42 
     43  {
     44    const startTime = ChromeUtils.now();
     45 
     46    const openPromises = [];
     47 
     48    for (let index = 0; index < 1000; index++) {
     49      const request = indexedDB.openForPrincipal(principal, name);
     50      const openPromise = IndexedDBUtils.requestFinished(request);
     51      openPromises.push(openPromise);
     52    }
     53 
     54    const databases = await Promise.all(openPromises);
     55 
     56    for (const database of databases) {
     57      database.close();
     58    }
     59 
     60    const endTime = ChromeUtils.now();
     61 
     62    const timeDelta = endTime - startTime;
     63 
     64    info(`Opened databases in ${timeDelta} msec`);
     65  }
     66 
     67  info("Deleting database");
     68 
     69  {
     70    const startTime = ChromeUtils.now();
     71 
     72    const request = indexedDB.deleteForPrincipal(principal, name);
     73    await IndexedDBUtils.requestFinished(request);
     74 
     75    const endTime = ChromeUtils.now();
     76 
     77    const timeDelta = endTime - startTime;
     78 
     79    info(`Deleted database in ${timeDelta} msec`);
     80  }
     81 }