diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /storage/test/unit/test_persist_journal.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/test/unit/test_persist_journal.js')
-rw-r--r-- | storage/test/unit/test_persist_journal.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/storage/test/unit/test_persist_journal.js b/storage/test/unit/test_persist_journal.js new file mode 100644 index 0000000000..1eea5c703e --- /dev/null +++ b/storage/test/unit/test_persist_journal.js @@ -0,0 +1,89 @@ +/* Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests the journal persists on close. + +async function check_journal_persists(db, journal) { + let path = db.databaseFile.path; + info(`testing ${path}`); + await new Promise(resolve => { + db.executeSimpleSQLAsync(`PRAGMA journal_mode = ${journal}`, { + handleCompletion: resolve, + }); + }); + + await new Promise(resolve => { + db.executeSimpleSQLAsync("CREATE TABLE test (id INTEGER PRIMARY KEY)", { + handleCompletion: resolve, + }); + }); + + if (journal == "wal") { + Assert.ok(await IOUtils.exists(path + "-wal"), "-wal exists before close"); + Assert.greater( + (await IOUtils.stat(path + "-wal")).size, + 0, + "-wal size is non-zero" + ); + } else { + Assert.ok( + await IOUtils.exists(path + "-journal"), + "-journal exists before close" + ); + Assert.equal( + (await IOUtils.stat(path + "-journal")).size, + 0, + "-journal is truncated after every transaction" + ); + } + + await new Promise(resolve => db.asyncClose(resolve)); + + if (journal == "wal") { + Assert.ok(await IOUtils.exists(path + "-wal"), "-wal persists after close"); + Assert.equal( + (await IOUtils.stat(path + "-wal")).size, + 0, + "-wal has been truncated" + ); + } else { + Assert.ok( + await IOUtils.exists(path + "-journal"), + "-journal persists after close" + ); + Assert.equal( + (await IOUtils.stat(path + "-journal")).size, + 0, + "-journal has been truncated" + ); + } +} + +async function getDbPath(name) { + let path = PathUtils.join(PathUtils.profileDir, name + ".sqlite"); + Assert.ok(!(await IOUtils.exists(path)), "database should not exist"); + return path; +} + +add_task(async function () { + for (let journal of ["truncate", "wal"]) { + await check_journal_persists( + Services.storage.openDatabase( + new FileUtils.File(await getDbPath(`shared-${journal}`)) + ), + journal + ); + await check_journal_persists( + Services.storage.openUnsharedDatabase( + new FileUtils.File(await getDbPath(`unshared-${journal}`)) + ), + journal + ); + await check_journal_persists( + await openAsyncDatabase( + new FileUtils.File(await getDbPath(`async-${journal}`)) + ), + journal + ); + } +}); |