mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
pyln-testing: improve wait_for a bit
This 'fixes' the `wait_for` helper by removing a pointless final `time.sleep()`, thus potentially making the method return quicker. The old code could have had three final states: - success() := True - Timeout and success() := True - Timeout and success() := False The new code has just two final state: - success() := True - Timeout and success() := False It ensures the final `time.sleep()` is just the right amount before timeout. And more importantly making it more readable :-) Changelog-None
This commit is contained in:
committed by
Rusty Russell
parent
9da191e034
commit
d76ca6ed35
@@ -84,13 +84,14 @@ TIMEOUT = int(env("TIMEOUT", 180 if SLOW_MACHINE else 60))
|
|||||||
def wait_for(success, timeout=TIMEOUT):
|
def wait_for(success, timeout=TIMEOUT):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
interval = 0.25
|
interval = 0.25
|
||||||
while not success() and time.time() < start_time + timeout:
|
while not success():
|
||||||
time.sleep(interval)
|
time_left = start_time + timeout - time.time()
|
||||||
|
if time_left <= 0:
|
||||||
|
raise ValueError("Timeout while waiting for {}", success)
|
||||||
|
time.sleep(min(interval, time_left))
|
||||||
interval *= 2
|
interval *= 2
|
||||||
if interval > 5:
|
if interval > 5:
|
||||||
interval = 5
|
interval = 5
|
||||||
if time.time() > start_time + timeout:
|
|
||||||
raise ValueError("Error waiting for {}", success)
|
|
||||||
|
|
||||||
|
|
||||||
def write_config(filename, opts, regtest_opts=None, section_name='regtest'):
|
def write_config(filename, opts, regtest_opts=None, section_name='regtest'):
|
||||||
|
|||||||
Reference in New Issue
Block a user