LCOV - code coverage report
Current view: top level - src/test - chainstate_write_tests.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 100.0 % 21 21
Test Date: 2025-05-07 04:33:46 Functions: 100.0 % 3 3
Branches: 50.0 % 100 50

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <test/util/setup_common.h>
       6                 :             : #include <validation.h>
       7                 :             : #include <validationinterface.h>
       8                 :             : 
       9                 :             : #include <boost/test/unit_test.hpp>
      10                 :             : 
      11                 :             : BOOST_AUTO_TEST_SUITE(chainstate_write_tests)
      12                 :             : 
      13   [ +  -  +  -  :           7 : BOOST_FIXTURE_TEST_CASE(chainstate_write_interval, TestingSetup)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      14                 :             : {
      15                 :           2 :     struct TestSubscriber final : CValidationInterface {
      16                 :             :         bool m_did_flush{false};
      17                 :           1 :         void ChainStateFlushed(ChainstateRole, const CBlockLocator&) override
      18                 :             :         {
      19                 :           1 :             m_did_flush = true;
      20                 :           1 :         }
      21                 :             :     };
      22                 :             : 
      23                 :           1 :     const auto sub{std::make_shared<TestSubscriber>()};
      24   [ +  -  +  - ]:           2 :     m_node.validation_signals->RegisterSharedValidationInterface(sub);
      25   [ +  -  +  - ]:           1 :     auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()};
      26         [ +  - ]:           1 :     BlockValidationState state_dummy{};
      27                 :             : 
      28                 :             :     // The first periodic flush sets m_next_write and does not flush
      29         [ +  - ]:           1 :     chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
      30         [ +  - ]:           1 :     m_node.validation_signals->SyncWithValidationInterfaceQueue();
      31   [ +  -  +  - ]:           2 :     BOOST_CHECK(!sub->m_did_flush);
      32                 :             : 
      33                 :             :     // The periodic flush interval is between 50 and 70 minutes (inclusive)
      34         [ +  - ]:           1 :     SetMockTime(GetTime<std::chrono::minutes>() + 49min);
      35         [ +  - ]:           1 :     chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
      36         [ +  - ]:           1 :     m_node.validation_signals->SyncWithValidationInterfaceQueue();
      37   [ +  -  +  - ]:           2 :     BOOST_CHECK(!sub->m_did_flush);
      38                 :             : 
      39         [ +  - ]:           1 :     SetMockTime(GetTime<std::chrono::minutes>() + 70min);
      40         [ +  - ]:           1 :     chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
      41         [ +  - ]:           1 :     m_node.validation_signals->SyncWithValidationInterfaceQueue();
      42   [ +  -  +  - ]:           2 :     BOOST_CHECK(sub->m_did_flush);
      43         [ +  - ]:           2 : }
      44                 :             : 
      45                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1