Skip to content

Commit 69d4390

Browse files
committed
test: add coverage for wallet read write db deadlock
1 parent 12daf6f commit 69d4390

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

src/wallet/test/util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ namespace wallet {
2222
class CWallet;
2323
class WalletDatabase;
2424

25+
static const DatabaseFormat DATABASE_FORMATS[] = {
26+
#ifdef USE_SQLITE
27+
DatabaseFormat::SQLITE,
28+
#endif
29+
#ifdef USE_BDB
30+
DatabaseFormat::BERKELEY,
31+
#endif
32+
};
33+
2534
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
2635

2736
// Creates a copy of the provided database

src/wallet/test/wallet_tests.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,6 @@ BOOST_AUTO_TEST_CASE(ComputeTimeSmart)
426426
BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 5, 50, 600), 300);
427427
}
428428

429-
static const DatabaseFormat DATABASE_FORMATS[] = {
430-
#ifdef USE_SQLITE
431-
DatabaseFormat::SQLITE,
432-
#endif
433-
#ifdef USE_BDB
434-
DatabaseFormat::BERKELEY,
435-
#endif
436-
};
437-
438429
void TestLoadWallet(const std::string& name, DatabaseFormat format, std::function<void(std::shared_ptr<CWallet>)> f)
439430
{
440431
node::NodeContext node;

src/wallet/test/walletdb_tests.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <clientversion.h>
77
#include <streams.h>
88
#include <uint256.h>
9+
#include <wallet/test/util.h>
10+
#include <wallet/wallet.h>
911

1012
#include <boost/test/unit_test.hpp>
1113

@@ -27,5 +29,31 @@ BOOST_AUTO_TEST_CASE(walletdb_readkeyvalue)
2729
BOOST_CHECK_THROW(ssValue >> dummy, std::ios_base::failure);
2830
}
2931

32+
BOOST_AUTO_TEST_CASE(walletdb_read_write_deadlock)
33+
{
34+
// Exercises a db read write operation that shouldn't deadlock.
35+
for (const DatabaseFormat& db_format : DATABASE_FORMATS) {
36+
// Context setup
37+
DatabaseOptions options;
38+
options.require_format = db_format;
39+
DatabaseStatus status;
40+
bilingual_str error_string;
41+
std::unique_ptr<WalletDatabase> db = MakeDatabase(m_path_root / strprintf("wallet_%d_.dat", db_format).c_str(), options, status, error_string);
42+
BOOST_ASSERT(status == DatabaseStatus::SUCCESS);
43+
44+
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(db)));
45+
wallet->m_keypool_size = 4;
46+
47+
// Create legacy spkm
48+
LOCK(wallet->cs_wallet);
49+
auto legacy_spkm = wallet->GetOrCreateLegacyScriptPubKeyMan();
50+
BOOST_CHECK(legacy_spkm->SetupGeneration(true));
51+
wallet->Flush();
52+
53+
// Now delete all records, which performs a read write operation.
54+
BOOST_CHECK(wallet->GetLegacyScriptPubKeyMan()->DeleteRecords());
55+
}
56+
}
57+
3058
BOOST_AUTO_TEST_SUITE_END()
3159
} // namespace wallet

0 commit comments

Comments
 (0)