From 9e2a723d5da4fc277a42fed37424f578e348ebf8 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Thu, 4 Jul 2024 21:43:16 +0200 Subject: [PATCH] test: Add arguments for creating a slimmer setup Adds more testing options for creating an environment without networking and a validation interface. This is useful for improving the performance of the utxo snapshot fuzz test, which constructs a new TestingSetup on each iteration. --- src/test/fuzz/utxo_snapshot.cpp | 8 +++++++- src/test/util/setup_common.cpp | 12 ++++++++---- src/test/util/setup_common.h | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/test/fuzz/utxo_snapshot.cpp b/src/test/fuzz/utxo_snapshot.cpp index 522c9c54eed..60d9d39b73f 100644 --- a/src/test/fuzz/utxo_snapshot.cpp +++ b/src/test/fuzz/utxo_snapshot.cpp @@ -31,7 +31,13 @@ void initialize_chain() FUZZ_TARGET(utxo_snapshot, .init = initialize_chain) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); - std::unique_ptr setup{MakeNoLogFileContext()}; + std::unique_ptr setup{ + MakeNoLogFileContext( + ChainType::REGTEST, + TestOpts{ + .setup_net = false, + .setup_validation_interface = false, + })}; const auto& node = setup->m_node; auto& chainman{*node.chainman}; diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 60f9261e7e1..b4dd07f257f 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -218,9 +218,11 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts) // We have to run a scheduler thread to prevent ActivateBestChain // from blocking due to queue overrun. - m_node.scheduler = std::make_unique(); - m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); }); - m_node.validation_signals = std::make_unique(std::make_unique(*m_node.scheduler)); + if (opts.setup_validation_interface) { + m_node.scheduler = std::make_unique(); + m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); }); + m_node.validation_signals = std::make_unique(std::make_unique(*m_node.scheduler)); + } m_node.fee_estimator = std::make_unique(FeeestPath(*m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES); bilingual_str error{}; @@ -255,7 +257,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts) ChainTestingSetup::~ChainTestingSetup() { if (m_node.scheduler) m_node.scheduler->stop(); - m_node.validation_signals->FlushBackgroundCallbacks(); + if (m_node.validation_signals) m_node.validation_signals->FlushBackgroundCallbacks(); m_node.connman.reset(); m_node.banman.reset(); m_node.addrman.reset(); @@ -306,6 +308,8 @@ TestingSetup::TestingSetup( LoadVerifyActivateChainstate(); + if (!opts.setup_net) return; + m_node.netgroupman = std::make_unique(/*asmap=*/std::vector()); m_node.addrman = std::make_unique(*m_node.netgroupman, /*deterministic=*/false, diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index e8b630af941..220bf6e422d 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -52,6 +52,8 @@ struct TestOpts { std::vector extra_args{}; bool coins_db_in_memory{true}; bool block_tree_db_in_memory{true}; + bool setup_net{true}; + bool setup_validation_interface{true}; }; /** Basic testing setup.