Skip to content

Commit 48c9ba1

Browse files
committed
Merge bitcoin/bitcoin#34137: test: Avoid hard time.sleep(1) in feature_init.py
fa727e3 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 fa727e3 rkrux: tACK fa727e3 janb84: tACK fa727e3 Tree-SHA512: 7b59496a1b9b8044548423ad517ff03e98521685cf65499cd0ef499d6fd3d72ad374c92ca815436675ed6ae7be508a5a1afce699b804a384d7aee6a195d8d972
2 parents d861c38 + fa727e3 commit 48c9ba1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test/functional/feature_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import shutil
1111
import signal
1212
import subprocess
13-
import time
1413

1514
from test_framework.test_framework import BitcoinTestFramework
1615
from test_framework.test_node import (
@@ -272,7 +271,8 @@ def break_wait_test(self):
272271
# returns early it will return the current block height.
273272
self.log.debug(f"Calling waitforblockheight with {self.rpc_timeout} sec RPC timeout")
274273
fut = ex.submit(node.waitforblockheight, height=current_height+1, timeout=self.rpc_timeout*1000*2)
275-
time.sleep(1)
274+
275+
self.wait_until(lambda: any(c["method"] == "waitforblockheight" for c in node.cli.getrpcinfo()["active_commands"]))
276276

277277
self.log.debug(f"Sending break signal to pid {node.process.pid}")
278278
if platform.system() == 'Windows':

0 commit comments

Comments
 (0)