diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /storage/test | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/test')
-rw-r--r-- | storage/test/gtest/test_interruptSynchronousConnection.cpp | 33 | ||||
-rw-r--r-- | storage/test/unit/test_connection_online_backup.js | 60 |
2 files changed, 73 insertions, 20 deletions
diff --git a/storage/test/gtest/test_interruptSynchronousConnection.cpp b/storage/test/gtest/test_interruptSynchronousConnection.cpp index dfa19bc86e..b29337e720 100644 --- a/storage/test/gtest/test_interruptSynchronousConnection.cpp +++ b/storage/test/gtest/test_interruptSynchronousConnection.cpp @@ -8,6 +8,7 @@ #include "storage_test_harness.h" +#include "mozilla/Atomics.h" #include "mozilla/SpinEventLoopUntil.h" class SynchronousConnectionInterruptionTest : public ::testing::Test { @@ -31,7 +32,9 @@ class SynchronousConnectionInterruptionTest : public ::testing::Test { nsCOMPtr<nsIThread> mThread; - bool mDone = false; + mozilla::Atomic<nsresult> mRv = mozilla::Atomic<nsresult>(NS_ERROR_FAILURE); + + mozilla::Atomic<bool> mDone{false}; }; TEST_F(SynchronousConnectionInterruptionTest, @@ -41,12 +44,11 @@ TEST_F(SynchronousConnectionInterruptionTest, const uint32_t delayMs = 500; ASSERT_EQ(NS_OK, mThread->DelayedDispatch( - NS_NewRunnableFunction( - "InterruptRunnable", - [this]() { - ASSERT_EQ(NS_OK, mConnection->Interrupt()); - mDone = true; - }), + NS_NewRunnableFunction("InterruptRunnable", + [this]() { + mRv = mConnection->Interrupt(); + mDone = true; + }), delayMs)); const nsCString infiniteQuery = @@ -56,10 +58,12 @@ TEST_F(SynchronousConnectionInterruptionTest, nsCOMPtr<mozIStorageStatement> stmt; ASSERT_EQ(NS_OK, mConnection->CreateStatement(infiniteQuery, getter_AddRefs(stmt))); + ASSERT_EQ(NS_ERROR_ABORT, stmt->Execute()); ASSERT_EQ(NS_OK, stmt->Finalize()); ASSERT_TRUE(mDone); + ASSERT_EQ(NS_OK, mRv); ASSERT_EQ(NS_OK, mConnection->Close()); } @@ -67,15 +71,16 @@ TEST_F(SynchronousConnectionInterruptionTest, TEST_F(SynchronousConnectionInterruptionTest, interruptAfterCloseWillFail) { ASSERT_EQ(NS_OK, mConnection->Close()); - ASSERT_EQ( - NS_OK, - mThread->Dispatch(NS_NewRunnableFunction("InterruptRunnable", [this]() { - ASSERT_EQ(NS_ERROR_NOT_INITIALIZED, mConnection->Interrupt()); - mDone = true; - }))); + ASSERT_EQ(NS_OK, mThread->Dispatch( + NS_NewRunnableFunction("InterruptRunnable", [this]() { + mRv = mConnection->Interrupt(); + mDone = true; + }))); ASSERT_TRUE(mozilla::SpinEventLoopUntil("interruptAfterCloseWillFail"_ns, - [this]() { return mDone; })); + [this]() -> bool { return mDone; })); + + ASSERT_EQ(NS_ERROR_NOT_INITIALIZED, mRv); ASSERT_EQ(NS_ERROR_NOT_INITIALIZED, mConnection->Close()); } diff --git a/storage/test/unit/test_connection_online_backup.js b/storage/test/unit/test_connection_online_backup.js index 3599d8c824..ca8e27e9a2 100644 --- a/storage/test/unit/test_connection_online_backup.js +++ b/storage/test/unit/test_connection_online_backup.js @@ -85,9 +85,15 @@ async function getPreparedAsyncDatabase() { * * @param {mozIStorageAsyncConnection} connection * A connection to a database that should be copied. + * @param {number} [pagesPerStep] + * The number of pages to copy per step. If not supplied or is 0, falls back + * to the platform default which is currently 5. + * @param {number} [stepDelayMs] + * The number of milliseconds to wait between copying step. If not supplied + * or is 0, falls back to the platform default which is currently 250. * @returns {Promise<nsIFile>} */ -async function createCopy(connection) { +async function createCopy(connection, pagesPerStep, stepDelayMs) { let destFilePath = PathUtils.join(PathUtils.profileDir, BACKUP_FILE_NAME); let destFile = await IOUtils.getFile(destFilePath); Assert.ok( @@ -96,10 +102,15 @@ async function createCopy(connection) { ); await new Promise(resolve => { - connection.backupToFileAsync(destFile, result => { - Assert.ok(Components.isSuccessCode(result)); - resolve(result); - }); + connection.backupToFileAsync( + destFile, + result => { + Assert.ok(Components.isSuccessCode(result)); + resolve(result); + }, + pagesPerStep, + stepDelayMs + ); }); return destFile; @@ -121,7 +132,7 @@ async function assertSuccessfulCopy(file, expectedEntries = TEST_ROWS) { await executeSimpleSQLAsync(conn, "PRAGMA page_size", resultSet => { let result = resultSet.getNextRow(); - Assert.equal(TEST_PAGE_SIZE, result.getResultByIndex(0).getAsUint32()); + Assert.equal(TEST_PAGE_SIZE, result.getResultByIndex(0)); }); let stmt = conn.createAsyncStatement("SELECT COUNT(*) FROM test"); @@ -191,6 +202,36 @@ add_task(async function test_backupToFileAsync_during_insert() { }); /** + * Tests that alternative pages-per-step and step delay values can be set when + * calling backupToFileAsync. + */ +add_task(async function test_backupToFileAsync_during_insert() { + let newConnection = await getPreparedAsyncDatabase(); + + // Let's try some higher values... + let copyFile = await createCopy(newConnection, 15, 500); + Assert.ok( + await IOUtils.exists(copyFile.path), + "A new file was created by backupToFileAsync" + ); + + await assertSuccessfulCopy(copyFile); + await IOUtils.remove(copyFile.path); + + // And now we'll try some lower values... + copyFile = await createCopy(newConnection, 1, 25); + Assert.ok( + await IOUtils.exists(copyFile.path), + "A new file was created by backupToFileAsync" + ); + + await assertSuccessfulCopy(copyFile); + await IOUtils.remove(copyFile.path); + + await asyncClose(newConnection); +}); + +/** * Tests the behaviour of backupToFileAsync as exposed through Sqlite.sys.mjs. */ add_task(async function test_backupToFileAsync_via_Sqlite_module() { @@ -206,6 +247,13 @@ add_task(async function test_backupToFileAsync_via_Sqlite_module() { await assertSuccessfulCopy(copyFile); await IOUtils.remove(copyFile.path); + + // Also check that we can plumb through pagesPerStep and stepDelayMs. + await moduleConnection.backup(copyFilePath, 15, 500); + Assert.ok(await IOUtils.exists(copyFilePath), "A new file was created"); + await assertSuccessfulCopy(copyFile); + await IOUtils.remove(copyFile.path); + await moduleConnection.close(); await asyncClose(xpcomConnection); }); |