From c1fa5a0f15f23aa275084e36abc739556938051d Mon Sep 17 00:00:00 2001 From: MacroFake Date: Fri, 10 Jun 2022 12:37:19 +0200 Subject: [PATCH] Merge bitcoin/bitcoin#25312: test: Fix port collisions caused by p2p_getaddr_caching.py ea54ba2f42f6d0b23570c665c2369f977bf55cf6 [test] Fix port collisions caused by p2p_getaddr_caching.py (dergoegge) f9682e75ac184a62c7e29287882df34c25303033 [test_framework] Set PortSeed.n directly after initialising params (dergoegge) Pull request description: This PR fixes the issue mentioned [here](https://github.com/bitcoin/bitcoin/pull/25096#discussion_r892558783), to avoid port collisions between nodes spun up by the test framework. Top commit has no ACKs. Tree-SHA512: ec9159f0af90db636f7889d664c24e1430cf2bcb3c02a9ab2dcfe531b2a4d18f6e3a0f8ba73071bdf2f7db518df9d5d86a9cd06695e67644d20fe4515fac32b7 --- test/functional/p2p_getaddr_caching.py | 10 ++++------ test/functional/test_framework/test_framework.py | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/test/functional/p2p_getaddr_caching.py b/test/functional/p2p_getaddr_caching.py index 1d7d324cf0..d892a13412 100755 --- a/test/functional/p2p_getaddr_caching.py +++ b/test/functional/p2p_getaddr_caching.py @@ -12,8 +12,7 @@ from test_framework.p2p import ( from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, - PORT_MIN, - PORT_RANGE, + p2p_port, ) # As defined in net_processing. @@ -42,10 +41,9 @@ class AddrReceiver(P2PInterface): class AddrTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 - # Start onion ports after p2p and rpc ports. - port = PORT_MIN + 2 * PORT_RANGE - self.onion_port1 = port - self.onion_port2 = port + 1 + # Use some of the remaining p2p ports for the onion binds. + self.onion_port1 = p2p_port(1) + self.onion_port2 = p2p_port(2) self.extra_args = [ [f"-bind=127.0.0.1:{self.onion_port1}=onion", f"-bind=127.0.0.1:{self.onion_port2}=onion"], ] diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 14824eeef9..6bdccc9a4a 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -236,11 +236,11 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): # source: https://stackoverflow.com/questions/48796169/how-to-fix-ipykernel-launcher-py-error-unrecognized-arguments-in-jupyter/56349168#56349168 parser.add_argument("-f", "--fff", help="a dummy argument to fool ipython", default="1") + PortSeed.n = self.options.port_seed + def setup(self): """Call this method to start up the test framework object with options set.""" - PortSeed.n = self.options.port_seed - check_json_precision() self.options.cachedir = os.path.abspath(self.options.cachedir)