diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index f3f1405bcb..d10689c3ee 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -403,6 +403,15 @@ CBlock TestChainSetup::CreateBlock(const std::vector& txns, TestChainSetup::~TestChainSetup() { + // Allow tx index to catch up with the block index cause otherwise + // we might be destroying it while scheduler still has some work for it + // e.g. via BlockConnected signal + int64_t time_start = GetTimeMillis(); + while (!g_txindex->BlockUntilSyncedToCurrentChain()) { + static constexpr int64_t timeout_ms = 10 * 1000; + assert(time_start + timeout_ms > GetTimeMillis()); + UninterruptibleSleep(std::chrono::milliseconds{100}); + } g_txindex->Interrupt(); g_txindex->Stop(); g_txindex.reset();