refactor(qa-tests): Extract InternalDurationTestMixin for use in next commit
What changed, and why it matters
This is a small test-code cleanup that moves a helper for calculating RPC timeout into a reusable mixin. It does not change Bitcoin Core's production code, network behavior, or wallet security. There is no vulnerability here.
No security action needed. Treat as ordinary test refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors test/functional/feature_framework_startup_failures.py by extracting InternalDurationTestMixin from InternalTestMixin. The new mixin adds an option parser argument for node_start_duration and a get_reasonable_rpc_timeout() method. TestWrongRpcPortStartupFailure now inherits from InternalDurationTestMixin and calls the helper instead of inlining the timeout formula. The logic is identical; only code organization changes.
Changed components
test/functional/feature_framework_startup_failures.pyInspect captured patch +10 / −4
diff --git a/test/functional/feature_framework_startup_failures.py b/test/functional/feature_framework_startup_failures.py
index 1fdeb083..1949952e 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."
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.