diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 5d723a2c468..87f0b31cad8 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -60,6 +60,7 @@ #include #include +#include #include #include @@ -230,6 +231,12 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts) // Use synchronous task runner while fuzzing to avoid non-determinism G_FUZZING ? std::make_unique(std::make_unique()) : std::make_unique(std::make_unique(*m_node.scheduler)); + { + // Ensure deterministic coverage by waiting for m_service_thread to be running + std::promise promise; + m_node.scheduler->scheduleFromNow([&promise] { promise.set_value(); }, 0ms); + promise.get_future().wait(); + } } bilingual_str error{}; @@ -247,7 +254,8 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts) .check_block_index = 1, .notifications = *m_node.notifications, .signals = m_node.validation_signals.get(), - .worker_threads_num = 2, + // Use no worker threads while fuzzing to avoid non-determinism + .worker_threads_num = G_FUZZING ? 0 : 2, }; if (opts.min_validation_cache) { chainman_opts.script_execution_cache_bytes = 0;