diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2023-12-20 12:07:13 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2024-01-15 20:09:22 -0300 |
commit | fdf9f66909a354a95f4b7c5f092f0e9fbe1baa7c (patch) | |
tree | 8e93b59d21a004b2f7806464800cdf1014afc88c /src/wallet/test | |
parent | 05c4c5a4347018d6d0e81b8f12cf5bdcaa8b4a89 (diff) | |
download | bitcoin-fdf9f66909a354a95f4b7c5f092f0e9fbe1baa7c.tar.xz |
test: wallet db, exercise deadlock after write failure
Diffstat (limited to 'src/wallet/test')
-rw-r--r-- | src/wallet/test/db_tests.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp index d341e84d9b..c6b2154efd 100644 --- a/src/wallet/test/db_tests.cpp +++ b/src/wallet/test/db_tests.cpp @@ -205,5 +205,29 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_byte_test) } } +BOOST_AUTO_TEST_CASE(db_availability_after_write_error) +{ + // Ensures the database remains accessible without deadlocking after a write error. + // To simulate the behavior, record overwrites are disallowed, and the test verifies + // that the database remains active after failing to store an existing record. + for (const auto& database : TestDatabases(m_path_root)) { + // Write original record + std::unique_ptr<DatabaseBatch> batch = database->MakeBatch(); + std::string key = "key"; + std::string value = "value"; + std::string value2 = "value_2"; + BOOST_CHECK(batch->Write(key, value)); + // Attempt to overwrite the record (expect failure) + BOOST_CHECK(!batch->Write(key, value2, /*fOverwrite=*/false)); + // Successfully overwrite the record + BOOST_CHECK(batch->Write(key, value2, /*fOverwrite=*/true)); + // Sanity-check; read and verify the overwritten value + std::string read_value; + BOOST_CHECK(batch->Read(key, read_value)); + BOOST_CHECK_EQUAL(read_value, value2); + } +} + + BOOST_AUTO_TEST_SUITE_END() } // namespace wallet |