TestChain100Setup enqueues 100 validation events from blocks. Unit tests using that setup and their own validation events may run into non-determinism and even intermittent test failures.
Fix all issues by draining the pending validation events in the ctor.
This can be tested with a diff like:
diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp
index 128f14a6d5..2ea3ec8d4c 100644
--- a/src/validationinterface.cpp
+++ b/src/validationinterface.cpp
@@ -14,2 +14,3 @@
#include <primitives/transaction.h>
+#include <random.h>
#include <util/check.h>
@@ -156,2 +157,4 @@ void ValidationSignals::SyncWithValidationInterfaceQueue()
+static FastRandomContext g_rnd{};
+
// Use a macro instead of a function for conditional logging to prevent
@@ -168,2 +171,3 @@ void ValidationSignals::SyncWithValidationInterfaceQueue()
LOG_EVENT("%s", local_log_msg); \
+ UninterruptibleSleep(1ms * g_rnd.randrange(105)); \
local_event(); \
and then running the test scan_for_wallet_transactions_attach_chain a few times.
Or master (or the first commit), it should fail with: error: scan_for_wallet_transactions_attach_chain": check wallet->mapWallet.size() == static_cast<size_t>(NEW_BLOCKS + 1) has failed [7 != 6].
(Also included is a commit to move-only the many rescan tests to a separate file)
(Also included is a commit to fix unsafe index shutdowns in tests)