From fa17cdb191de71cdb4151408450aa9b3eaea6cb8 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 28 Mar 2025 14:25:34 +0100 Subject: [PATCH] test: Avoid script check worker threads while fuzzing Threads may execute their function any time after they are spawned, so coverage could be non-deterministic. Fix this, * for the script check worker threads by disabling them while fuzzing. * for the scheduler thread by waiting for it to fully start and run the service queue. --- src/test/util/setup_common.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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;