Skip to content

Commit 331a25c

Browse files
committed
test: indexes, avoid creating threads when sync runs synchronously
The indexes test call StartBackgroundSync(), which spawns a thread to run Sync(), only for the test thread to wait for it to complete by calling IndexWaitSynced(). So, since the sync is performed synchronously, we can skip the extra thread creation entirely and call Sync() directly.
1 parent ae02413 commit 331a25c

File tree

6 files changed

+4
-55
lines changed

6 files changed

+4
-55
lines changed

src/test/blockfilter_index_tests.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <node/miner.h>
1313
#include <pow.h>
1414
#include <test/util/blockfilter.h>
15-
#include <test/util/index.h>
1615
#include <test/util/setup_common.h>
1716
#include <validation.h>
1817

@@ -143,10 +142,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
143142
// BlockUntilSyncedToCurrentChain should return false before index is started.
144143
BOOST_CHECK(!filter_index.BlockUntilSyncedToCurrentChain());
145144

146-
BOOST_REQUIRE(filter_index.StartBackgroundSync());
147-
148-
// Allow filter index to catch up with the block index.
149-
IndexWaitSynced(filter_index, *Assert(m_node.shutdown_signal));
145+
filter_index.Sync();
150146

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

src/test/coinstatsindex_tests.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <index/coinstatsindex.h>
77
#include <interfaces/chain.h>
88
#include <kernel/coinstats.h>
9-
#include <test/util/index.h>
109
#include <test/util/setup_common.h>
1110
#include <test/util/validation.h>
1211
#include <validation.h>
@@ -33,9 +32,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
3332
// is started.
3433
BOOST_CHECK(!coin_stats_index.BlockUntilSyncedToCurrentChain());
3534

36-
BOOST_REQUIRE(coin_stats_index.StartBackgroundSync());
37-
38-
IndexWaitSynced(coin_stats_index, *Assert(m_node.shutdown_signal));
35+
coin_stats_index.Sync();
3936

4037
// Check that CoinStatsIndex works for genesis block.
4138
const CBlockIndex* genesis_block_index;
@@ -85,8 +82,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_unclean_shutdown, TestChain100Setup)
8582
{
8683
CoinStatsIndex index{interfaces::MakeChain(m_node), 1 << 20};
8784
BOOST_REQUIRE(index.Init());
88-
BOOST_REQUIRE(index.StartBackgroundSync());
89-
IndexWaitSynced(index, *Assert(m_node.shutdown_signal));
85+
index.Sync();
9086
std::shared_ptr<const CBlock> new_block;
9187
CBlockIndex* new_block_index = nullptr;
9288
{

src/test/txindex_tests.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <chainparams.h>
77
#include <index/txindex.h>
88
#include <interfaces/chain.h>
9-
#include <test/util/index.h>
109
#include <test/util/setup_common.h>
1110
#include <validation.h>
1211

@@ -30,10 +29,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
3029
// BlockUntilSyncedToCurrentChain should return false before txindex is started.
3130
BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain());
3231

33-
BOOST_REQUIRE(txindex.StartBackgroundSync());
34-
35-
// Allow tx index to catch up with the block index.
36-
IndexWaitSynced(txindex, *Assert(m_node.shutdown_signal));
32+
txindex.Sync();
3733

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

src/test/util/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL
66
blockfilter.cpp
77
coins.cpp
88
coverage.cpp
9-
index.cpp
109
json.cpp
1110
logging.cpp
1211
mining.cpp

src/test/util/index.cpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/test/util/index.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)