Skip to content

Commit a1f0b8b

Browse files
author
MarcoFalke
committed
Merge #21634: tests: Skip SQLite fsyncs while testing
41f891d tests: Skip SQLite fsyncs while testing (Andrew Chow) Pull request description: Since we want tests to run quickly, and since tests do a lot more db operations than expected we expect to see in actual usage, we disable sqlite's syncing behavior to make db operations run much faster. This syncing behavior is necessary for normal operation as it helps guarantee that data won't become lost or corrupted, but in tests, we don't care about that. Fixes #21628 ACKs for top commit: vasild: ACK 41f891d Tree-SHA512: f36f969a182c622691ae5113573a3250e8d367437e83a1a9d3d2b55dd3a9cdf3c6474169a7bd271007bb9ce47f585aa7a6aeae6eebbaeb02d79409b02f47fd8b
2 parents 1f14130 + 41f891d commit a1f0b8b

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

src/dummywallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
5050
"-flushwallet",
5151
"-privdb",
5252
"-walletrejectlongchains",
53+
"-unsafesqlitesync",
5354
});
5455
}
5556

src/wallet/init.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
8282
argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
8383
#endif
8484

85+
#ifdef USE_SQLITE
86+
argsman.AddArg("-unsafesqlitesync", "Set SQLite synchronous=OFF to disable waiting for the database to sync to disk. This is unsafe and can cause data loss and corruption. This option is only used by tests to improve their performance (default: false)", ArgsManager::ALLOW_BOOL | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
87+
#else
88+
argsman.AddHiddenArgs({"-unsafesqlitesync"});
89+
#endif
90+
8591
argsman.AddArg("-walletrejectlongchains", strprintf("Wallet will not create transactions that violate mempool chain limits (default: %u)", DEFAULT_WALLET_REJECT_LONG_CHAINS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
8692

8793
argsman.AddHiddenArgs({"-zapwallettxes"});

src/wallet/sqlite.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ void SQLiteDatabase::Open()
233233
throw std::runtime_error(strprintf("SQLiteDatabase: Failed to enable fullfsync: %s\n", sqlite3_errstr(ret)));
234234
}
235235

236+
if (gArgs.GetBoolArg("-unsafesqlitesync", false)) {
237+
// Use normal synchronous mode for the journal
238+
LogPrintf("WARNING SQLite is configured to not wait for data to be flushed to disk. Data loss and corruption may occur.\n");
239+
ret = sqlite3_exec(m_db, "PRAGMA synchronous = OFF", nullptr, nullptr, nullptr);
240+
if (ret != SQLITE_OK) {
241+
throw std::runtime_error(strprintf("SQLiteDatabase: Failed to set synchronous mode to OFF: %s\n", sqlite3_errstr(ret)));
242+
}
243+
}
244+
236245
// Make the table for our key-value pairs
237246
// First check that the main table exists
238247
sqlite3_stmt* check_main_stmt{nullptr};

src/wallet/test/wallet_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup)
692692
//! rescanning where new transactions in new blocks could be lost.
693693
BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
694694
{
695+
gArgs.ForceSetArg("-unsafesqlitesync", "1");
695696
// Create new wallet with known key and unload it.
696697
auto wallet = TestLoadWallet(*m_node.chain);
697698
CKey key;
@@ -787,6 +788,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
787788

788789
BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
789790
{
791+
gArgs.ForceSetArg("-unsafesqlitesync", "1");
790792
auto wallet = TestLoadWallet(*m_node.chain);
791793
CKey key;
792794
key.MakeNewKey(true);

test/functional/test_framework/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ def write_config(config_path, *, n, chain, extra_config=""):
374374
f.write("upnp=0\n")
375375
f.write("natpmp=0\n")
376376
f.write("shrinkdebugfile=0\n")
377+
# To improve SQLite wallet performance so that the tests don't timeout, use -unsafesqlitesync
378+
f.write("unsafesqlitesync=1\n")
377379
f.write(extra_config)
378380

379381

0 commit comments

Comments
 (0)