Skip to content

Commit cc9dcdd

Browse files
kwvgPastaPastaPasta
authored andcommitted
test: migrate TestChainSetup's g_txindex guardrails
1 parent d7b7bbd commit cc9dcdd

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/test/util/setup_common.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <streams.h>
4141
#include <spork.h>
4242
#include <txdb.h>
43+
#include <test/util/index.h>
4344
#include <util/strencodings.h>
4445
#include <util/string.h>
4546
#include <util/time.h>
@@ -316,12 +317,7 @@ void TestChainSetup::mineBlocks(int num_blocks)
316317
assert(g_txindex->Start(::ChainstateActive()));
317318

318319
// Allow tx index to catch up with the block index.
319-
constexpr int64_t timeout_ms = 10 * 1000;
320-
int64_t time_start = GetTimeMillis();
321-
while (!g_txindex->BlockUntilSyncedToCurrentChain()) {
322-
assert(time_start + timeout_ms > GetTimeMillis());
323-
UninterruptibleSleep(std::chrono::milliseconds{100});
324-
}
320+
IndexWaitSynced(*g_txindex);
325321
}
326322

327323
CBlock TestChainSetup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
@@ -410,14 +406,9 @@ TestChainSetup::~TestChainSetup()
410406
// Allow tx index to catch up with the block index cause otherwise
411407
// we might be destroying it while scheduler still has some work for it
412408
// e.g. via BlockConnected signal
413-
int64_t time_start = GetTimeMillis();
414-
while (!g_txindex->BlockUntilSyncedToCurrentChain()) {
415-
static constexpr int64_t timeout_ms = 10 * 1000;
416-
assert(time_start + timeout_ms > GetTimeMillis());
417-
UninterruptibleSleep(std::chrono::milliseconds{100});
418-
}
419-
g_txindex->Interrupt();
409+
IndexWaitSynced(*g_txindex);
420410
g_txindex->Stop();
411+
SyncWithValidationInterfaceQueue();
421412
g_txindex.reset();
422413
SetMockTime(0);
423414
}

0 commit comments

Comments
 (0)