mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
test: Add check_interval parameter to wait_until
This also replaces two sleep calls in functional tests with wait_until
This commit is contained in:
parent
16c87d91fd
commit
5468a23eb9
5 changed files with 12 additions and 12 deletions
|
@ -579,13 +579,13 @@ class P2PInterface(P2PConnection):
|
|||
|
||||
# Connection helper methods
|
||||
|
||||
def wait_until(self, test_function_in, *, timeout=60, check_connected=True):
|
||||
def wait_until(self, test_function_in, *, timeout=60, check_connected=True, check_interval=0.05):
|
||||
def test_function():
|
||||
if check_connected:
|
||||
assert self.is_connected
|
||||
return test_function_in()
|
||||
|
||||
wait_until_helper_internal(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor)
|
||||
wait_until_helper_internal(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor, check_interval=check_interval)
|
||||
|
||||
def wait_for_connect(self, *, timeout=60):
|
||||
test_function = lambda: self.is_connected
|
||||
|
|
|
@ -787,8 +787,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
self.sync_blocks(nodes)
|
||||
self.sync_mempools(nodes)
|
||||
|
||||
def wait_until(self, test_function, timeout=60):
|
||||
return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.options.timeout_factor)
|
||||
def wait_until(self, test_function, timeout=60, check_interval=0.05):
|
||||
return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.options.timeout_factor, check_interval=check_interval)
|
||||
|
||||
# Private helper methods. These should not be accessed by the subclass test scripts.
|
||||
|
||||
|
|
|
@ -838,8 +838,8 @@ class TestNode():
|
|||
self.mocktime += seconds
|
||||
self.setmocktime(self.mocktime)
|
||||
|
||||
def wait_until(self, test_function, timeout=60):
|
||||
return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.timeout_factor)
|
||||
def wait_until(self, test_function, timeout=60, check_interval=0.05):
|
||||
return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.timeout_factor, check_interval=check_interval)
|
||||
|
||||
|
||||
class TestNodeCLIAttr:
|
||||
|
|
|
@ -289,7 +289,7 @@ def ensure_for(*, duration, f, check_interval=0.2):
|
|||
time.sleep(check_interval)
|
||||
|
||||
|
||||
def wait_until_helper_internal(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0):
|
||||
def wait_until_helper_internal(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0, check_interval=0.05):
|
||||
"""Sleep until the predicate resolves to be True.
|
||||
|
||||
Warning: Note that this method is not recommended to be used in tests as it is
|
||||
|
@ -313,7 +313,7 @@ def wait_until_helper_internal(predicate, *, attempts=float('inf'), timeout=floa
|
|||
if predicate():
|
||||
return
|
||||
attempt += 1
|
||||
time.sleep(0.05)
|
||||
time.sleep(check_interval)
|
||||
|
||||
# Print the cause of the timeout
|
||||
predicate_source = "''''\n" + inspect.getsource(predicate) + "'''"
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
Test Inactive HD Chains.
|
||||
"""
|
||||
import shutil
|
||||
import time
|
||||
|
||||
from test_framework.authproxy import JSONRPCException
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
|
@ -75,12 +74,13 @@ class InactiveHDChainsTest(BitcoinTestFramework):
|
|||
self.generate(self.nodes[0], 1)
|
||||
|
||||
# Wait for the test wallet to see the transaction
|
||||
while True:
|
||||
def is_tx_available(txid):
|
||||
try:
|
||||
test_wallet.gettransaction(txid)
|
||||
break
|
||||
return True
|
||||
except JSONRPCException:
|
||||
time.sleep(0.1)
|
||||
return False
|
||||
self.nodes[0].wait_until(lambda: is_tx_available(txid), timeout=10, check_interval=0.1)
|
||||
|
||||
if encrypt:
|
||||
# The test wallet will not be able to generate the topped up keypool
|
||||
|
|
Loading…
Reference in a new issue