aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2023-11-28 19:11:52 +0000
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2023-11-28 19:11:52 +0000
commitfd4c6a10f2285f16c5d0215eb56a3060441f3ef2 (patch)
tree939a409705591dec3bc3f22c94eedad363721295 /src
parent31ce305d46a191621aaa78a73fa4bbc7e58d8ed0 (diff)
test: Setup networking globally
Diffstat (limited to 'src')
-rw-r--r--src/common/system.h2
-rw-r--r--src/test/util/setup_common.cpp11
-rw-r--r--src/test/util_tests.cpp3
3 files changed, 14 insertions, 2 deletions
diff --git a/src/common/system.h b/src/common/system.h
index 40206aaa01..08ed419a45 100644
--- a/src/common/system.h
+++ b/src/common/system.h
@@ -21,7 +21,7 @@
int64_t GetStartupTime();
void SetupEnvironment();
-bool SetupNetworking();
+[[nodiscard]] bool SetupNetworking();
#ifndef WIN32
std::string ShellEscape(const std::string& arg);
#endif
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index 22fdf132c7..fcfb33f5e7 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -49,6 +49,7 @@
#include <txdb.h>
#include <txmempool.h>
#include <util/chaintype.h>
+#include <util/check.h>
#include <util/rbf.h>
#include <util/strencodings.h>
#include <util/string.h>
@@ -88,6 +89,15 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
return os;
}
+struct NetworkSetup
+{
+ NetworkSetup()
+ {
+ Assert(SetupNetworking());
+ }
+};
+static NetworkSetup g_networksetup_instance;
+
BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args)
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()},
m_args{}
@@ -130,7 +140,6 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vecto
LogInstance().StartLogging();
m_node.kernel = std::make_unique<kernel::Context>();
SetupEnvironment();
- SetupNetworking();
ValidationCacheSizes validation_cache_sizes{};
ApplyArgsManOptions(*m_node.args, validation_cache_sizes);
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 7d6c96ab40..4d812544bd 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -1218,6 +1218,9 @@ BOOST_AUTO_TEST_CASE(test_LockDirectory)
// has released the lock as we would expect by probing it.
int processstatus;
BOOST_CHECK_EQUAL(write(fd[1], &LockCommand, 1), 1);
+ // The following line invokes the ~CNetCleanup dtor without
+ // a paired SetupNetworking call. This is acceptable as long as
+ // ~CNetCleanup is a no-op for non-Windows platforms.
BOOST_CHECK_EQUAL(write(fd[1], &ExitCommand, 1), 1);
BOOST_CHECK_EQUAL(waitpid(pid, &processstatus, 0), pid);
BOOST_CHECK_EQUAL(processstatus, 0);