test_cache_size.js (2047B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // This file tests that dbs of various page sizes are using the right cache 5 // size (bug 703113). 6 7 /** 8 * In order to change the cache size, we must open a DB, change the page 9 * size, create a table, close the DB, then re-open the DB. We then check 10 * the cache size after reopening. 11 * 12 * @param dbOpener 13 * function that opens the DB specified in file 14 * @param file 15 * file holding the database 16 * @param pageSize 17 * the DB's page size 18 * @param expectedCacheSize 19 * the expected cache size for the given page size 20 */ 21 function check_size(dbOpener, file, pageSize, expectedCacheSize) { 22 // Open the DB, immediately change its page size. 23 let db = dbOpener(file); 24 db.executeSimpleSQL("PRAGMA page_size = " + pageSize); 25 26 // Check the page size change worked. 27 let stmt = db.createStatement("PRAGMA page_size"); 28 Assert.ok(stmt.executeStep()); 29 Assert.equal(stmt.row.page_size, pageSize); 30 stmt.finalize(); 31 32 // Create a simple table. 33 db.executeSimpleSQL("CREATE TABLE test ( id INTEGER PRIMARY KEY )"); 34 35 // Close and re-open the DB. 36 db.close(); 37 db = dbOpener(file); 38 39 // Check cache size is as expected. 40 stmt = db.createStatement("PRAGMA cache_size"); 41 Assert.ok(stmt.executeStep()); 42 Assert.equal(stmt.row.cache_size, expectedCacheSize); 43 stmt.finalize(); 44 } 45 46 function new_file(name) { 47 let file = Services.dirsvc.get("ProfD", Ci.nsIFile); 48 file.append(name + ".sqlite"); 49 Assert.ok(!file.exists()); 50 return file; 51 } 52 53 function run_test() { 54 const kExpectedCacheSize = -2048; // 2MiB 55 56 let pageSizes = [1024, 4096, 32768]; 57 58 for (let i = 0; i < pageSizes.length; i++) { 59 let pageSize = pageSizes[i]; 60 check_size( 61 getDatabase, 62 new_file("shared" + pageSize), 63 pageSize, 64 kExpectedCacheSize 65 ); 66 check_size( 67 Services.storage.openUnsharedDatabase, 68 new_file("unshared" + pageSize), 69 pageSize, 70 kExpectedCacheSize 71 ); 72 } 73 }