mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#27988: Use same timeout for all index sync
This commit is contained in:
parent
a9e3b9f2db
commit
d7b7bbd425
@ -9,6 +9,7 @@ EXTRA_LIBRARIES += \
|
||||
|
||||
TEST_UTIL_H = \
|
||||
test/util/blockfilter.h \
|
||||
test/util/index.h \
|
||||
test/util/logging.h \
|
||||
test/util/mining.h \
|
||||
test/util/net.h \
|
||||
@ -21,6 +22,7 @@ libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAG
|
||||
libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libtest_util_a_SOURCES = \
|
||||
test/util/blockfilter.cpp \
|
||||
test/util/index.cpp \
|
||||
test/util/logging.cpp \
|
||||
test/util/mining.cpp \
|
||||
test/util/net.cpp \
|
||||
|
@ -17,8 +17,8 @@
|
||||
#include <script/standard.h>
|
||||
#include <spork.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>
|
||||
@ -141,12 +141,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
|
||||
BOOST_REQUIRE(filter_index.Start(::ChainstateActive()));
|
||||
|
||||
// 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.
|
||||
{
|
||||
|
@ -3,28 +3,15 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <index/coinstatsindex.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>
|
||||
|
||||
#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{1 << 20, true};
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include <chainparams.h>
|
||||
#include <index/txindex.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>
|
||||
@ -31,12 +31,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
|
||||
BOOST_REQUIRE(txindex.Start(::ChainstateActive()));
|
||||
|
||||
// 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();
|
||||
|
18
src/test/util/index.cpp
Normal file
18
src/test/util/index.cpp
Normal file
@ -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);
|
||||
}
|
||||
}
|
13
src/test/util/index.h
Normal file
13
src/test/util/index.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user