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

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2512-test-less-hard-sleep changing 1 files +2 −2
  1. maflcko commented at 1:46 pm on December 22, 2025: member

    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.

  2. DrahtBot added the label Tests on Dec 22, 2025
  3. DrahtBot commented at 1:46 pm on December 22, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34137.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK rkrux, Sjors, janb84

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  4. maflcko force-pushed on Dec 22, 2025
  5. DrahtBot added the label CI failed on Dec 22, 2025
  6. DrahtBot commented at 1:54 pm on December 22, 2025: contributor

    🚧 At least one of the CI tasks failed. Task lint: https://github.com/bitcoin/bitcoin/actions/runs/20433712257/job/58709973844 LLM reason (✨ experimental): Lint Python code failed due to unused import (time) in test/functional/feature_init.py, causing lint check to exit with error.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  7. DrahtBot removed the label CI failed on Dec 22, 2025
  8. in test/functional/feature_init.py:272 in fa5082a650 outdated
    270@@ -272,7 +271,14 @@ def break_wait_test(self):
    271             # returns early it will return the current block height.
    272             self.log.debug(f"Calling waitforblockheight with {self.rpc_timeout} sec RPC timeout")
    


    Sjors commented at 3:26 am on December 23, 2025:
    nit: I think the comment should say “with 2x RPC timeout (2x {self.rpc_timeout} sec)”

    maflcko commented at 7:08 am on December 23, 2025:

    No? The rpc timeout is half in reality, since it is never re-set after the init loop, which sets it to half.

    edit: Also, this seems unrelated to the changes here. I am not touching this line.

  9. test: Avoid hard time.sleep(1) in feature_init.py fa727e3ec9
  10. in test/functional/feature_init.py:275 in fa5082a650
    270@@ -272,7 +271,14 @@ def break_wait_test(self):
    271             # returns early it will return the current block height.
    272             self.log.debug(f"Calling waitforblockheight with {self.rpc_timeout} sec RPC timeout")
    273             fut = ex.submit(node.waitforblockheight, height=current_height+1, timeout=self.rpc_timeout*1000*2)
    274-            time.sleep(1)
    275+
    276+            def waitforblockheight_active():
    


    Sjors commented at 3:32 am on December 23, 2025:

    So IIUC this checks if there’s any active commands. If not, it throws KeyError so the wait ends. If there is one, it ensure the first running command is waitforblockheight and then ends the wait.

    A bit hard to follow. Maybe instead check whether any of the active_commands is waitforblockheight?


    maflcko commented at 7:08 am on December 23, 2025:

    So IIUC this checks if there’s any active commands. If not, it throws KeyError so the wait ends.

    No it does not. It waits until the condition is true.

    In any case, I am happy to push any diff or commit, if someone writes one.


    rkrux commented at 12:31 pm on December 23, 2025:

    In any case, I am happy to push any diff or commit, if someone writes one.

     0diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py
     1index eb45340da7..56f3e61d21 100755
     2--- a/test/functional/feature_init.py
     3+++ b/test/functional/feature_init.py
     4@@ -274,7 +274,7 @@ class InitTest(BitcoinTestFramework):
     5 
     6             def waitforblockheight_active():
     7                 try:
     8-                    return node.cli.getrpcinfo()["active_commands"][0]["method"] == "waitforblockheight"
     9+                    return any(active_command["method"] == "waitforblockheight" for active_command in node.cli.getrpcinfo()["active_commands"])
    10                 except KeyError:
    11                     return False
    

    maflcko commented at 12:44 pm on December 23, 2025:
    thx, i pushed something like that

    rkrux commented at 2:08 pm on December 23, 2025:
    The latest push seems better than what I suggested because the KeyError exception need not be looked for now.
  11. maflcko force-pushed on Dec 23, 2025
  12. rkrux approved
  13. rkrux commented at 2:10 pm on December 23, 2025: contributor

    tACK fa727e3

    Seems like an esoteric change but I will have it because I like it.

  14. Sjors commented at 1:41 am on December 24, 2025: member

    utACK fa727e3ec984106371eeedb34d7bbbbc3dcce4ff

    Thanks, this is easier to read than before: #34137 (review)

    It’s also an improvement over sleep(1), because the code specifically says what it’s waiting for.

  15. janb84 commented at 12:10 pm on December 24, 2025: contributor

    tACK fa727e3ec984106371eeedb34d7bbbbc3dcce4ff

    PR removes arbitrary sleep(1) for a “readiness” check, this improves reliability of test. (on my machine there is a 1 sec reduction on test duration; Master: Feature-init.py (15s) - this PR Feature-init.py (14s) )

  16. fanquake merged this on Dec 27, 2025
  17. fanquake closed this on Dec 27, 2025

  18. sedited referenced this in commit f8db928648 on Dec 27, 2025
  19. joshdoman referenced this in commit 57661ceac9 on Dec 27, 2025
  20. maflcko deleted the branch on Dec 29, 2025
  21. fanquake referenced this in commit 7568bc3ab0 on Jan 5, 2026
  22. fanquake commented at 12:10 pm on January 5, 2026: member
    Backported to 30.x in #34192.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-28 15:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me