Skip to content

Commit fd4c6a1

Browse files
committed
test: Setup networking globally
1 parent 31ce305 commit fd4c6a1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/common/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
int64_t GetStartupTime();
2222

2323
void SetupEnvironment();
24-
bool SetupNetworking();
24+
[[nodiscard]] bool SetupNetworking();
2525
#ifndef WIN32
2626
std::string ShellEscape(const std::string& arg);
2727
#endif

src/test/util/setup_common.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <txdb.h>
5050
#include <txmempool.h>
5151
#include <util/chaintype.h>
52+
#include <util/check.h>
5253
#include <util/rbf.h>
5354
#include <util/strencodings.h>
5455
#include <util/string.h>
@@ -88,6 +89,15 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
8889
return os;
8990
}
9091

92+
struct NetworkSetup
93+
{
94+
NetworkSetup()
95+
{
96+
Assert(SetupNetworking());
97+
}
98+
};
99+
static NetworkSetup g_networksetup_instance;
100+
91101
BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args)
92102
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()},
93103
m_args{}
@@ -130,7 +140,6 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vecto
130140
LogInstance().StartLogging();
131141
m_node.kernel = std::make_unique<kernel::Context>();
132142
SetupEnvironment();
133-
SetupNetworking();
134143

135144
ValidationCacheSizes validation_cache_sizes{};
136145
ApplyArgsManOptions(*m_node.args, validation_cache_sizes);

src/test/util_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,9 @@ BOOST_AUTO_TEST_CASE(test_LockDirectory)
12181218
// has released the lock as we would expect by probing it.
12191219
int processstatus;
12201220
BOOST_CHECK_EQUAL(write(fd[1], &LockCommand, 1), 1);
1221+
// The following line invokes the ~CNetCleanup dtor without
1222+
// a paired SetupNetworking call. This is acceptable as long as
1223+
// ~CNetCleanup is a no-op for non-Windows platforms.
12211224
BOOST_CHECK_EQUAL(write(fd[1], &ExitCommand, 1), 1);
12221225
BOOST_CHECK_EQUAL(waitpid(pid, &processstatus, 0), pid);
12231226
BOOST_CHECK_EQUAL(processstatus, 0);

0 commit comments

Comments
 (0)