Tests should not attempt to create network connections over the internet because that has unpredictable timing and outcome. It could also reveal the location (IP address) where somebody is running Bitcoin Core tests, if the target address is very specific, e.g. not github.com:443
, but 1.2.3.4:8333
for example. See #31339.
#31349 is an attempt to detect such cases in CI. In the discussions on that PR a complementary idea came up - to use a mocked socket from unit tests to detect such usage. That could be done in addition if there is support for it and if not too complicated.
I guess, if this is to be done, either CreateSock()
should be changed from BasicTestingSetup
to throw right away or return a mocked Sock
object that has a real underlying socket and throws on attempts to create non-loopback connections.