Fix corner-case in handling of remaining retry time
authorKlaus Aehlig <aehlig@google.com>
Thu, 19 Sep 2013 16:12:21 +0000 (18:12 +0200)
committerKlaus Aehlig <aehlig@google.com>
Fri, 20 Sep 2013 12:21:35 +0000 (14:21 +0200)
Consider a remaining time of 0 as already timed out. Otherwise,
there is no guarantee that calling utils.Retry with timeout 0
will call the function precisely once; it might run in time
shorter than the resolution of timer.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/utils/retry.py

index cc7541c..12d1014 100644 (file)
@@ -170,11 +170,11 @@ def Retry(fn, delay, timeout, args=None, wait_fn=time.sleep,
 
     remaining_time = end_time - _time_fn()
 
-    if remaining_time < 0.0:
+    if remaining_time <= 0.0:
       # pylint: disable=W0142
       raise RetryTimeout(*retry_args)
 
-    assert remaining_time >= 0.0
+    assert remaining_time > 0.0
 
     if calc_delay is None:
       wait_fn(remaining_time)