From d7f703c1f1a88e2fa7226adf43c45a794b4e07c6 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Tue, 8 Jul 2025 21:47:53 +0200 Subject: [PATCH] refactor(qa-tests): Extract InternalDurationTestMixin for use in next commit --- .../feature_framework_startup_failures.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/functional/feature_framework_startup_failures.py b/test/functional/feature_framework_startup_failures.py index 1fdeb083034..1949952e7e8 100755 --- a/test/functional/feature_framework_startup_failures.py +++ b/test/functional/feature_framework_startup_failures.py @@ -107,20 +107,26 @@ class InternalTestMixin: # Just here to silence unrecognized argument error, we actually read the value in the if-main at the bottom. parser.add_argument("--internal_test", dest="internal_never_read", help="ONLY TO BE USED WHEN TEST RELAUNCHES ITSELF") -class TestWrongRpcPortStartupFailure(InternalTestMixin, BitcoinTestFramework): +class InternalDurationTestMixin(InternalTestMixin): def add_options(self, parser): + # Receives the previously measured duration for node startup + RPC connection establishment. parser.add_argument("--internal_node_start_duration", dest="node_start_duration", help="ONLY TO BE USED WHEN TEST RELAUNCHES ITSELF", type=float) InternalTestMixin.add_options(self, parser) + def get_reasonable_rpc_timeout(self): + # 2 * the measured test startup duration should be enough. + # Divide by timeout_factor to counter multiplication in BitcoinTestFramework. + return max(3, 2 * self.options.node_start_duration) / self.options.timeout_factor + +class TestWrongRpcPortStartupFailure(InternalDurationTestMixin, BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 # Override RPC listen port to something TestNode isn't expecting so that # we are unable to establish an RPC connection. self.extra_args = [[f"-rpcport={rpc_port(2)}"]] # Override the timeout to avoid waiting unnecessarily long to realize - # nothing is on that port. Divide by timeout_factor to counter - # multiplication in base, 2 * node_start_duration should be enough. - self.rpc_timeout = max(3, 2 * self.options.node_start_duration) / self.options.timeout_factor + # nothing is on that port. + self.rpc_timeout = self.get_reasonable_rpc_timeout() def run_test(self): assert False, "Should have failed earlier during startup."