test_multipleOpensInSequence.js (2373B)
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 open requests to the same database, issued one after 23 * another. Only one should run at a time, and each should start promptly after 24 * the previous finishes. 25 * 26 * If scheduling or cleanup is slow, this test may fail due to timeout. 27 * 28 * Note: Not only the number of requests, but also the number of live (open) 29 * databases may affect performance. 30 * 31 * Note: This test could theoretically be combined with its counterpart in a 32 * single file with multiple tasks, but they are intentionally split to: 33 * - Avoid interference between test cases 34 * - Make it obvious which scenario timed out (serial vs. parallel) 35 */ 36 37 /* exported testSteps */ 38 async function testSteps() { 39 const principal = PrincipalUtils.createPrincipal("https://example.com"); 40 const name = "multipleOpensInSequence"; 41 42 info("Opening databases"); 43 44 { 45 const startTime = ChromeUtils.now(); 46 47 const databases = []; 48 49 for (let index = 0; index < 1000; index++) { 50 const request = indexedDB.openForPrincipal(principal, name); 51 const database = await IndexedDBUtils.requestFinished(request); 52 databases.push(database); 53 } 54 55 for (const database of databases) { 56 database.close(); 57 } 58 59 const endTime = ChromeUtils.now(); 60 61 const timeDelta = endTime - startTime; 62 63 info(`Opened databases in ${timeDelta} msec`); 64 } 65 66 info("Deleting database"); 67 68 { 69 const startTime = ChromeUtils.now(); 70 71 const request = indexedDB.deleteForPrincipal(principal, name); 72 await IndexedDBUtils.requestFinished(request); 73 74 const endTime = ChromeUtils.now(); 75 76 const timeDelta = endTime - startTime; 77 78 info(`Deleted database in ${timeDelta} msec`); 79 } 80 }