diff --git a/src/common/system.h b/src/common/system.h index 40206aaa01d..08ed419a458 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 22fdf132c72..fcfb33f5e79 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -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& 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(); 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 7d6c96ab402..4d812544bde 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);