Merge bitcoin/bitcoin#34137: test: Avoid hard time.sleep(1) in feature_init.py

fa727e3ec984106371eeedb34d7bbbbc3dcce4ff test: Avoid hard time.sleep(1) in feature_init.py (MarcoFalke)

Pull request description:

  Using a hard-coded `time.sleep` in the tests is usually confusing and brittle. For example, the one in `break_wait_test`:

  * Is confusing, because it does not explain why it is needed.
  * On fast hardware will just lead to a useless delay.
  * On slow hardware may lead to an intermittent, and confusing test failure.

  Fix all issues by replacing it with the proper condition to wait on.

ACKs for top commit:
  Sjors:
    utACK fa727e3ec984106371eeedb34d7bbbbc3dcce4ff
  rkrux:
    tACK fa727e3
  janb84:
    tACK fa727e3ec984106371eeedb34d7bbbbc3dcce4ff

Tree-SHA512: 7b59496a1b9b8044548423ad517ff03e98521685cf65499cd0ef499d6fd3d72ad374c92ca815436675ed6ae7be508a5a1afce699b804a384d7aee6a195d8d972
This commit is contained in:
merge-script 2025-12-27 16:07:16 +00:00
commit 48c9ba1e97
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -10,7 +10,6 @@ import platform
import shutil
import signal
import subprocess
import time
from test_framework.test_framework import BitcoinTestFramework
from test_framework.test_node import (
@ -272,7 +271,8 @@ class InitTest(BitcoinTestFramework):
# returns early it will return the current block height.
self.log.debug(f"Calling waitforblockheight with {self.rpc_timeout} sec RPC timeout")
fut = ex.submit(node.waitforblockheight, height=current_height+1, timeout=self.rpc_timeout*1000*2)
time.sleep(1)
self.wait_until(lambda: any(c["method"] == "waitforblockheight" for c in node.cli.getrpcinfo()["active_commands"]))
self.log.debug(f"Sending break signal to pid {node.process.pid}")
if platform.system() == 'Windows':