| 18 | BOOST_AUTO_TEST_SUITE(chainstate_write_tests) |
| 19 | |
| 20 | BOOST_FIXTURE_TEST_CASE(chainstate_write_interval, TestingSetup) |
| 21 | { |
| 22 | struct TestSubscriber final : CValidationInterface { |
| 23 | bool m_did_flush{false}; |
| 24 | void ChainStateFlushed(const ChainstateRole&, const CBlockLocator&) override |
| 25 | { |
| 26 | m_did_flush = true; |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | const auto sub{std::make_shared<TestSubscriber>()}; |
| 31 | m_node.validation_signals->RegisterSharedValidationInterface(sub); |
| 32 | auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()}; |
| 33 | BlockValidationState state_dummy{}; |
| 34 | FakeNodeClock clock{}; |
| 35 | |
| 36 | // The first periodic flush sets m_next_write and does not flush |
| 37 | chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC); |
| 38 | m_node.validation_signals->SyncWithValidationInterfaceQueue(); |
| 39 | BOOST_CHECK(!sub->m_did_flush); |
| 40 | |
| 41 | // The periodic flush interval is between 50 and 70 minutes (inclusive) |
| 42 | clock += DATABASE_WRITE_INTERVAL_MIN - 1min; |
| 43 | chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC); |
| 44 | m_node.validation_signals->SyncWithValidationInterfaceQueue(); |
| 45 | BOOST_CHECK(!sub->m_did_flush); |
| 46 | |
| 47 | clock += DATABASE_WRITE_INTERVAL_MAX; |
| 48 | chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC); |
| 49 | m_node.validation_signals->SyncWithValidationInterfaceQueue(); |
| 50 | BOOST_CHECK(sub->m_did_flush); |
| 51 | } |
| 52 | |
| 53 | // Test that we do PERIODIC flushes inside ActivateBestChain. |
| 54 | // This is necessary for reindex-chainstate to be able to periodically flush |
nothing calls this directly
no test coverage detected