@@ -205,5 +205,29 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_byte_test)
205205 }
206206}
207207
208+ BOOST_AUTO_TEST_CASE (db_availability_after_write_error)
209+ {
210+ // Ensures the database remains accessible without deadlocking after a write error.
211+ // To simulate the behavior, record overwrites are disallowed, and the test verifies
212+ // that the database remains active after failing to store an existing record.
213+ for (const auto & database : TestDatabases (m_path_root)) {
214+ // Write original record
215+ std::unique_ptr<DatabaseBatch> batch = database->MakeBatch ();
216+ std::string key = " key" ;
217+ std::string value = " value" ;
218+ std::string value2 = " value_2" ;
219+ BOOST_CHECK (batch->Write (key, value));
220+ // Attempt to overwrite the record (expect failure)
221+ BOOST_CHECK (!batch->Write (key, value2, /* fOverwrite=*/ false ));
222+ // Successfully overwrite the record
223+ BOOST_CHECK (batch->Write (key, value2, /* fOverwrite=*/ true ));
224+ // Sanity-check; read and verify the overwritten value
225+ std::string read_value;
226+ BOOST_CHECK (batch->Read (key, read_value));
227+ BOOST_CHECK_EQUAL (read_value, value2);
228+ }
229+ }
230+
231+
208232BOOST_AUTO_TEST_SUITE_END ()
209233} // namespace wallet
0 commit comments