mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Merge #21634: tests: Skip SQLite fsyncs while testing
41f891da50
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: ACK41f891da50
Tree-SHA512: f36f969a182c622691ae5113573a3250e8d367437e83a1a9d3d2b55dd3a9cdf3c6474169a7bd271007bb9ce47f585aa7a6aeae6eebbaeb02d79409b02f47fd8b
This commit is contained in:
commit
a1f0b8b62e
5 changed files with 20 additions and 0 deletions
|
@ -50,6 +50,7 @@ void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
|
|||
"-flushwallet",
|
||||
"-privdb",
|
||||
"-walletrejectlongchains",
|
||||
"-unsafesqlitesync",
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,12 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
|
|||
argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
|
||||
#endif
|
||||
|
||||
#ifdef USE_SQLITE
|
||||
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);
|
||||
#else
|
||||
argsman.AddHiddenArgs({"-unsafesqlitesync"});
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
argsman.AddHiddenArgs({"-zapwallettxes"});
|
||||
|
|
|
@ -233,6 +233,15 @@ void SQLiteDatabase::Open()
|
|||
throw std::runtime_error(strprintf("SQLiteDatabase: Failed to enable fullfsync: %s\n", sqlite3_errstr(ret)));
|
||||
}
|
||||
|
||||
if (gArgs.GetBoolArg("-unsafesqlitesync", false)) {
|
||||
// Use normal synchronous mode for the journal
|
||||
LogPrintf("WARNING SQLite is configured to not wait for data to be flushed to disk. Data loss and corruption may occur.\n");
|
||||
ret = sqlite3_exec(m_db, "PRAGMA synchronous = OFF", nullptr, nullptr, nullptr);
|
||||
if (ret != SQLITE_OK) {
|
||||
throw std::runtime_error(strprintf("SQLiteDatabase: Failed to set synchronous mode to OFF: %s\n", sqlite3_errstr(ret)));
|
||||
}
|
||||
}
|
||||
|
||||
// Make the table for our key-value pairs
|
||||
// First check that the main table exists
|
||||
sqlite3_stmt* check_main_stmt{nullptr};
|
||||
|
|
|
@ -692,6 +692,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup)
|
|||
//! rescanning where new transactions in new blocks could be lost.
|
||||
BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
|
||||
{
|
||||
gArgs.ForceSetArg("-unsafesqlitesync", "1");
|
||||
// Create new wallet with known key and unload it.
|
||||
auto wallet = TestLoadWallet(*m_node.chain);
|
||||
CKey key;
|
||||
|
@ -787,6 +788,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
|
||||
{
|
||||
gArgs.ForceSetArg("-unsafesqlitesync", "1");
|
||||
auto wallet = TestLoadWallet(*m_node.chain);
|
||||
CKey key;
|
||||
key.MakeNewKey(true);
|
||||
|
|
|
@ -374,6 +374,8 @@ def write_config(config_path, *, n, chain, extra_config=""):
|
|||
f.write("upnp=0\n")
|
||||
f.write("natpmp=0\n")
|
||||
f.write("shrinkdebugfile=0\n")
|
||||
# To improve SQLite wallet performance so that the tests don't timeout, use -unsafesqlitesync
|
||||
f.write("unsafesqlitesync=1\n")
|
||||
f.write(extra_config)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue