Skip to content

Commit fa17cdb

Browse files
author
MarcoFalke
committed
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.
1 parent fa900bb commit fa17cdb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/test/util/setup_common.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <walletinitinterface.h>
6161

6262
#include <algorithm>
63+
#include <future>
6364
#include <functional>
6465
#include <stdexcept>
6566

@@ -230,6 +231,12 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
230231
// Use synchronous task runner while fuzzing to avoid non-determinism
231232
G_FUZZING ? std::make_unique<ValidationSignals>(std::make_unique<util::ImmediateTaskRunner>()) :
232233
std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(*m_node.scheduler));
234+
{
235+
// Ensure deterministic coverage by waiting for m_service_thread to be running
236+
std::promise<void> promise;
237+
m_node.scheduler->scheduleFromNow([&promise] { promise.set_value(); }, 0ms);
238+
promise.get_future().wait();
239+
}
233240
}
234241

235242
bilingual_str error{};
@@ -247,7 +254,8 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
247254
.check_block_index = 1,
248255
.notifications = *m_node.notifications,
249256
.signals = m_node.validation_signals.get(),
250-
.worker_threads_num = 2,
257+
// Use no worker threads while fuzzing to avoid non-determinism
258+
.worker_threads_num = G_FUZZING ? 0 : 2,
251259
};
252260
if (opts.min_validation_cache) {
253261
chainman_opts.script_execution_cache_bytes = 0;

0 commit comments

Comments
 (0)