summaryrefslogtreecommitdiff
path: root/storage/test/unit/test_chunk_growth.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /storage/test/unit/test_chunk_growth.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloaduxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'storage/test/unit/test_chunk_growth.js')
-rw-r--r--storage/test/unit/test_chunk_growth.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/storage/test/unit/test_chunk_growth.js b/storage/test/unit/test_chunk_growth.js
new file mode 100644
index 0000000000..2cf91fe166
--- /dev/null
+++ b/storage/test/unit/test_chunk_growth.js
@@ -0,0 +1,52 @@
+// This file tests SQLITE_FCNTL_CHUNK_SIZE behaves as expected
+
+function run_sql(d, sql) {
+ var stmt = d.createStatement(sql);
+ stmt.execute();
+ stmt.finalize();
+}
+
+function new_file(name) {
+ var file = dirSvc.get("ProfD", Ci.nsIFile);
+ file.append(name);
+ return file;
+}
+
+function get_size(name) {
+ return new_file(name).fileSize;
+}
+
+function run_test() {
+ const filename = "chunked.sqlite";
+ const CHUNK_SIZE = 512 * 1024;
+ var d = getDatabase(new_file(filename));
+ try {
+ d.setGrowthIncrement(CHUNK_SIZE, "");
+ } catch (e) {
+ if (e.result != Cr.NS_ERROR_FILE_TOO_BIG) {
+ throw e;
+ }
+ print("Too little free space to set CHUNK_SIZE!");
+ return;
+ }
+ run_sql(d, "CREATE TABLE bloat(data varchar)");
+
+ var orig_size = get_size(filename);
+ /* Dump in at least 32K worth of data.
+ * While writing ensure that the file size growth in chunksize set above.
+ */
+ const str1024 = new Array(1024).join("T");
+ for (var i = 0; i < 32; i++) {
+ run_sql(d, "INSERT INTO bloat VALUES('" + str1024 + "')");
+ var size = get_size(filename);
+ // Must not grow in small increments.
+ do_check_true(size == orig_size || size >= CHUNK_SIZE);
+ }
+ /* In addition to growing in chunk-size increments, the db
+ * should shrink in chunk-size increments too.
+ */
+ run_sql(d, "DELETE FROM bloat");
+ run_sql(d, "VACUUM");
+ do_check_true(get_size(filename) >= CHUNK_SIZE);
+}
+