Skip to content

Commit 47ab006

Browse files
committed
Merge bitcoin/bitcoin#27988: test: Use same timeout for all index sync
fa08624 test: Use same timeout for all index sync (MarcoFalke) Pull request description: Seems odd to use different timeouts. Fix this by using the same timeout for all syncs. May also fix bitcoin/bitcoin#27355 or at least make it less frequent? ACKs for top commit: mzumsande: code review ACK fa08624 Tree-SHA512: a61619247c97f3a88dd19eb3f200adedd120e6da8c4e4f2cf83621545b8c289dbad77e16f13cf7973a090f7b2c3391cb0297f09b0cc95fe4f55de21ae247670f
2 parents b5ebeb3 + fa08624 commit 47ab006

File tree

6 files changed

+38
-28
lines changed

6 files changed

+38
-28
lines changed

src/Makefile.test_util.include

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ TEST_UTIL_H = \
1111
test/util/blockfilter.h \
1212
test/util/chainstate.h \
1313
test/util/coins.h \
14+
test/util/index.h \
1415
test/util/json.h \
1516
test/util/logging.h \
1617
test/util/mining.h \
@@ -34,6 +35,7 @@ libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
3435
libtest_util_a_SOURCES = \
3536
test/util/blockfilter.cpp \
3637
test/util/coins.cpp \
38+
test/util/index.cpp \
3739
test/util/json.cpp \
3840
test/util/logging.cpp \
3941
test/util/mining.cpp \

src/test/blockfilter_index_tests.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <pow.h>
1313
#include <script/standard.h>
1414
#include <test/util/blockfilter.h>
15+
#include <test/util/index.h>
1516
#include <test/util/setup_common.h>
16-
#include <util/time.h>
1717
#include <validation.h>
1818

1919
#include <boost/test/unit_test.hpp>
@@ -142,12 +142,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
142142
BOOST_REQUIRE(filter_index.Start());
143143

144144
// Allow filter index to catch up with the block index.
145-
constexpr auto timeout{10s};
146-
const auto time_start{SteadyClock::now()};
147-
while (!filter_index.BlockUntilSyncedToCurrentChain()) {
148-
BOOST_REQUIRE(time_start + timeout > SteadyClock::now());
149-
UninterruptibleSleep(std::chrono::milliseconds{100});
150-
}
145+
IndexWaitSynced(filter_index);
151146

152147
// Check that filter index has all blocks that were in the chain before it started.
153148
{

src/test/coinstatsindex_tests.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,15 @@
66
#include <index/coinstatsindex.h>
77
#include <interfaces/chain.h>
88
#include <kernel/coinstats.h>
9+
#include <test/util/index.h>
910
#include <test/util/setup_common.h>
1011
#include <test/util/validation.h>
11-
#include <util/time.h>
1212
#include <validation.h>
1313

1414
#include <boost/test/unit_test.hpp>
1515

16-
#include <chrono>
17-
1816
BOOST_AUTO_TEST_SUITE(coinstatsindex_tests)
1917

20-
static void IndexWaitSynced(BaseIndex& index)
21-
{
22-
// Allow the CoinStatsIndex to catch up with the block index that is syncing
23-
// in a background thread.
24-
const auto timeout = GetTime<std::chrono::seconds>() + 120s;
25-
while (!index.BlockUntilSyncedToCurrentChain()) {
26-
BOOST_REQUIRE(timeout > GetTime<std::chrono::milliseconds>());
27-
UninterruptibleSleep(100ms);
28-
}
29-
}
30-
3118
BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
3219
{
3320
CoinStatsIndex coin_stats_index{interfaces::MakeChain(m_node), 1 << 20, true};

src/test/txindex_tests.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <index/txindex.h>
77
#include <interfaces/chain.h>
88
#include <script/standard.h>
9+
#include <test/util/index.h>
910
#include <test/util/setup_common.h>
10-
#include <util/time.h>
1111
#include <validation.h>
1212

1313
#include <boost/test/unit_test.hpp>
@@ -32,12 +32,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
3232
BOOST_REQUIRE(txindex.Start());
3333

3434
// Allow tx index to catch up with the block index.
35-
constexpr auto timeout{10s};
36-
const auto time_start{SteadyClock::now()};
37-
while (!txindex.BlockUntilSyncedToCurrentChain()) {
38-
BOOST_REQUIRE(time_start + timeout > SteadyClock::now());
39-
UninterruptibleSleep(std::chrono::milliseconds{100});
40-
}
35+
IndexWaitSynced(txindex);
4136

4237
// Check that txindex excludes genesis block transactions.
4338
const CBlock& genesis_block = Params().GenesisBlock();

src/test/util/index.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2020-2022 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/index.h>
6+
7+
#include <index/base.h>
8+
#include <util/check.h>
9+
#include <util/time.h>
10+
11+
void IndexWaitSynced(BaseIndex& index)
12+
{
13+
const auto timeout{SteadyClock::now() + 120s};
14+
while (!index.BlockUntilSyncedToCurrentChain()) {
15+
Assert(timeout > SteadyClock::now());
16+
UninterruptibleSleep(100ms);
17+
}
18+
}

src/test/util/index.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2020-2022 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+
#ifndef BITCOIN_TEST_UTIL_INDEX_H
6+
#define BITCOIN_TEST_UTIL_INDEX_H
7+
8+
class BaseIndex;
9+
10+
/** Block until the index is synced to the current chain */
11+
void IndexWaitSynced(BaseIndex& index);
12+
13+
#endif // BITCOIN_TEST_UTIL_INDEX_H

0 commit comments

Comments
 (0)