test: Split large init_stress_test into two smaller functions
What changed, and why it matters
This is a harmless code cleanup in Bitcoin Core's test suite. A large test function was split into two smaller, easier-to-read functions. No production code or security behavior changed.
No action needed; this is a benign test-only refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors test/functional/feature_init.py by extracting check_clean_start() as a helper method and splitting init_stress_test() into init_stress_test_interrupt() and init_stress_test_removals(). The logic, assertions, and test coverage remain identical; only structure and readability improved.
Changed components
test/functional/feature_init.pyInspect captured patch +26 / −20
diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py
index f3572013..1ca1b15b 100755
--- a/test/functional/feature_init.py
+++ b/test/functional/feature_init.py
@@ -30,10 +30,17 @@ class InitTest(BitcoinTestFramework):
self.num_nodes = 1
self.uses_wallet = None
- def init_stress_test(self):
+ def check_clean_start(self, node, extra_args):
+ """Ensure that node restarts successfully after various interrupts."""
+ node.start(extra_args)
+ node.wait_for_rpc_connection()
+ height = node.getblockcount()
+ assert_equal(200, height)
+ self.wait_until(lambda: all(i["synced"] and i["best_block_height"] == height for i in node.getindexinfo().values()))
+
+ def init_stress_test_interrupt(self):
"""
- test terminating initialization after seeing a certain log line.
- - test removing certain essential files to test startup error paths.
"""
self.stop_node(0)
node = self.nodes[0]
@@ -48,21 +55,6 @@ class InitTest(BitcoinTestFramework):
node.process.terminate()
node.process.wait()
- def start_expecting_error(err_fragment, args):
- node.assert_start_raises_init_error(
- extra_args=args,
- expected_msg=err_fragment,
- match=ErrorMatch.PARTIAL_REGEX,
- )
-
- def check_clean_start(extra_args):
- """Ensure that node restarts successfully after various interrupts."""
- node.start(extra_args)
- node.wait_for_rpc_connection()
- height = node.getblockcount()
- assert_equal(200, height)
- self.wait_until(lambda: all(i["synced"] and i["best_block_height"] == height for i in node.getindexinfo().values()))
-
lines_to_terminate_after = [
b'Validating signatures for all blocks',
b'scheduler thread start',
@@ -102,10 +94,23 @@ class InitTest(BitcoinTestFramework):
# Prior to deleting/perturbing index files, start node with all indexes enabled.
# 'check_clean_start' will ensure indexes are synchronized (i.e., data exists to modify)
- check_clean_start(args)
+ self.check_clean_start(node, args)
self.stop_node(0)
+ def init_stress_test_removals(self):
+ """
+ - test removing certain essential files to test startup error paths.
+ """
self.log.info("Test startup errors after removing certain essential files")
+ node = self.nodes[0]
+ args = ['-txindex=1', '-blockfilterindex=1', '-coinstatsindex=1']
+
+ def start_expecting_error(err_fragment, args):
+ node.assert_start_raises_init_error(
+ extra_args=args,
+ expected_msg=err_fragment,
+ match=ErrorMatch.PARTIAL_REGEX,
+ )
deletion_rounds = [
{
@@ -191,7 +196,7 @@ class InitTest(BitcoinTestFramework):
self.log.debug(f"Restoring file from {bak_path} and restarting")
Path(bak_path).rename(target_file)
- check_clean_start(args)
+ self.check_clean_start(node, args)
self.stop_node(0)
self.log.info("Test startup errors after perturbing certain essential files")
@@ -292,7 +297,8 @@ class InitTest(BitcoinTestFramework):
def run_test(self):
self.init_pid_test()
- self.init_stress_test()
+ self.init_stress_test_interrupt()
+ self.init_stress_test_removals()
self.break_wait_test()
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.