diff --git a/src/test/validationinterface_tests.cpp b/src/test/validationinterface_tests.cpp index 1dee83aad..4c2d5751b 100644 --- a/src/test/validationinterface_tests.cpp +++ b/src/test/validationinterface_tests.cpp @@ -1,62 +1,59 @@ // Copyright (c) 2020 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include - #include #include #include +#include #include #include -BOOST_AUTO_TEST_SUITE(validationinterface_tests) +BOOST_FIXTURE_TEST_SUITE(validationinterface_tests, TestingSetup) class TestInterface : public CValidationInterface { public: TestInterface(std::function on_call = nullptr, std::function on_destroy = nullptr) : m_on_call(std::move(on_call)), m_on_destroy(std::move(on_destroy)) {} virtual ~TestInterface() { if (m_on_destroy) { m_on_destroy(); } } void BlockChecked(const CBlock &block, const CValidationState &state) override { if (m_on_call) { m_on_call(); } } static void Call() { CBlock block; CValidationState state; GetMainSignals().BlockChecked(block, state); } std::function m_on_call; std::function m_on_destroy; }; // Regression test to ensure UnregisterAllValidationInterfaces calls don't // destroy a validation interface while it is being called. Bug: // https://github.com/bitcoin/bitcoin/pull/18551 BOOST_AUTO_TEST_CASE(unregister_all_during_call) { bool destroyed = false; - - CScheduler scheduler; - GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); RegisterSharedValidationInterface(std::make_shared( [&] { // First call should decrements reference count 2 -> 1 UnregisterAllValidationInterfaces(); BOOST_CHECK(!destroyed); // Second call should not decrement reference count 1 -> 0 UnregisterAllValidationInterfaces(); BOOST_CHECK(!destroyed); }, [&] { destroyed = true; })); TestInterface::Call(); BOOST_CHECK(destroyed); } BOOST_AUTO_TEST_SUITE_END()