diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-06-28 12:20:05 +0200 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-06-28 12:45:36 +0200 |
commit | fa086248e57b89cc549a090f727c0978082727c0 (patch) | |
tree | 284aebf40759728ea7b0fa591564906b5dbd29e2 | |
parent | 7ee41217b3b3fe4d8b7eb4fd1d4577b9b33d466d (diff) |
test: Use same timeout for all index sync
-rw-r--r-- | src/Makefile.test_util.include | 2 | ||||
-rw-r--r-- | src/test/blockfilter_index_tests.cpp | 9 | ||||
-rw-r--r-- | src/test/coinstatsindex_tests.cpp | 15 | ||||
-rw-r--r-- | src/test/txindex_tests.cpp | 9 | ||||
-rw-r--r-- | src/test/util/index.cpp | 18 | ||||
-rw-r--r-- | src/test/util/index.h | 13 |
6 files changed, 38 insertions, 28 deletions
diff --git a/src/Makefile.test_util.include b/src/Makefile.test_util.include index 11b93ad13e..33c299f34c 100644 --- a/src/Makefile.test_util.include +++ b/src/Makefile.test_util.include @@ -11,6 +11,7 @@ TEST_UTIL_H = \ test/util/blockfilter.h \ test/util/chainstate.h \ test/util/coins.h \ + test/util/index.h \ test/util/json.h \ test/util/logging.h \ test/util/mining.h \ @@ -34,6 +35,7 @@ libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libtest_util_a_SOURCES = \ test/util/blockfilter.cpp \ test/util/coins.cpp \ + test/util/index.cpp \ test/util/json.cpp \ test/util/logging.cpp \ test/util/mining.cpp \ diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp index 1ff5d6cf59..24af51cce1 100644 --- a/src/test/blockfilter_index_tests.cpp +++ b/src/test/blockfilter_index_tests.cpp @@ -12,8 +12,8 @@ #include <pow.h> #include <script/standard.h> #include <test/util/blockfilter.h> +#include <test/util/index.h> #include <test/util/setup_common.h> -#include <util/time.h> #include <validation.h> #include <boost/test/unit_test.hpp> @@ -142,12 +142,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) BOOST_REQUIRE(filter_index.Start()); // Allow filter index to catch up with the block index. - constexpr auto timeout{10s}; - const auto time_start{SteadyClock::now()}; - while (!filter_index.BlockUntilSyncedToCurrentChain()) { - BOOST_REQUIRE(time_start + timeout > SteadyClock::now()); - UninterruptibleSleep(std::chrono::milliseconds{100}); - } + IndexWaitSynced(filter_index); // Check that filter index has all blocks that were in the chain before it started. { diff --git a/src/test/coinstatsindex_tests.cpp b/src/test/coinstatsindex_tests.cpp index 503a58076b..9dc88ea671 100644 --- a/src/test/coinstatsindex_tests.cpp +++ b/src/test/coinstatsindex_tests.cpp @@ -6,28 +6,15 @@ #include <index/coinstatsindex.h> #include <interfaces/chain.h> #include <kernel/coinstats.h> +#include <test/util/index.h> #include <test/util/setup_common.h> #include <test/util/validation.h> -#include <util/time.h> #include <validation.h> #include <boost/test/unit_test.hpp> -#include <chrono> - BOOST_AUTO_TEST_SUITE(coinstatsindex_tests) -static void IndexWaitSynced(BaseIndex& index) -{ - // Allow the CoinStatsIndex to catch up with the block index that is syncing - // in a background thread. - const auto timeout = GetTime<std::chrono::seconds>() + 120s; - while (!index.BlockUntilSyncedToCurrentChain()) { - BOOST_REQUIRE(timeout > GetTime<std::chrono::milliseconds>()); - UninterruptibleSleep(100ms); - } -} - BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) { CoinStatsIndex coin_stats_index{interfaces::MakeChain(m_node), 1 << 20, true}; diff --git a/src/test/txindex_tests.cpp b/src/test/txindex_tests.cpp index b666517ae2..2677502ef0 100644 --- a/src/test/txindex_tests.cpp +++ b/src/test/txindex_tests.cpp @@ -6,8 +6,8 @@ #include <index/txindex.h> #include <interfaces/chain.h> #include <script/standard.h> +#include <test/util/index.h> #include <test/util/setup_common.h> -#include <util/time.h> #include <validation.h> #include <boost/test/unit_test.hpp> @@ -32,12 +32,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup) BOOST_REQUIRE(txindex.Start()); // Allow tx index to catch up with the block index. - constexpr auto timeout{10s}; - const auto time_start{SteadyClock::now()}; - while (!txindex.BlockUntilSyncedToCurrentChain()) { - BOOST_REQUIRE(time_start + timeout > SteadyClock::now()); - UninterruptibleSleep(std::chrono::milliseconds{100}); - } + IndexWaitSynced(txindex); // Check that txindex excludes genesis block transactions. const CBlock& genesis_block = Params().GenesisBlock(); diff --git a/src/test/util/index.cpp b/src/test/util/index.cpp new file mode 100644 index 0000000000..2bda7b1773 --- /dev/null +++ b/src/test/util/index.cpp @@ -0,0 +1,18 @@ +// Copyright (c) 2020-2022 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 <test/util/index.h> + +#include <index/base.h> +#include <util/check.h> +#include <util/time.h> + +void IndexWaitSynced(BaseIndex& index) +{ + const auto timeout{SteadyClock::now() + 120s}; + while (!index.BlockUntilSyncedToCurrentChain()) { + Assert(timeout > SteadyClock::now()); + UninterruptibleSleep(100ms); + } +} diff --git a/src/test/util/index.h b/src/test/util/index.h new file mode 100644 index 0000000000..02030fd562 --- /dev/null +++ b/src/test/util/index.h @@ -0,0 +1,13 @@ +// Copyright (c) 2020-2022 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_TEST_UTIL_INDEX_H +#define BITCOIN_TEST_UTIL_INDEX_H + +class BaseIndex; + +/** Block until the index is synced to the current chain */ +void IndexWaitSynced(BaseIndex& index); + +#endif // BITCOIN_TEST_UTIL_INDEX_H |