MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_FIXTURE_TEST_CASE

Function BOOST_FIXTURE_TEST_CASE

src/test/chainstate_write_tests.cpp:20–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18BOOST_AUTO_TEST_SUITE(chainstate_write_tests)
19
20BOOST_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

Callers

nothing calls this directly

Calls 6

FlushStateToDiskMethod · 0.80
DisconnectTipMethod · 0.80
ActivateBestChainMethod · 0.80
TipMethod · 0.45

Tested by

no test coverage detected