Change in vdsm[master]: utils: Consider sleep time in deadline calculation

nsoffer at redhat.com nsoffer at redhat.com
Sat Sep 19 17:39:57 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: utils: Consider sleep time in deadline calculation
......................................................................

utils: Consider sleep time in deadline calculation

This patches fixes 2 utils.retry() broken tests:

- The special case when deadline has reached when an operation was done.
  Previously we use to sleep and perform another retry, now we bail out.

- The special case when deadline was not reached when an operation was
  done, but we don't have time for sleep (sleeping will reach or exceed
  the deadline). Previously we used to sleep and perform another retry,
  now we bail out.

Change-Id: I7f41c6b21e3432159c13d46cfe75d1f6236cbb8c
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/utils.py
M tests/utilsTests.py
2 files changed, 3 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/00/46400/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index caf4cc2..4a4b153 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -938,10 +938,7 @@
     if tries in [0, None]:
         tries = -1
 
-    if timeout in [0, None]:
-        timeout = -1
-
-    startTime = monotonic_time()
+    deadline = monotonic_time() + timeout if timeout else None
 
     while True:
         tries -= 1
@@ -951,7 +948,7 @@
             if tries == 0:
                 raise
 
-            if (timeout > 0) and ((monotonic_time() - startTime) > timeout):
+            if deadline and monotonic_time() + sleep >= deadline:
                 raise
 
             if stopCallback is not None and stopCallback():
diff --git a/tests/utilsTests.py b/tests/utilsTests.py
index d213de5..fd4f42e 100644
--- a/tests/utilsTests.py
+++ b/tests/utilsTests.py
@@ -44,7 +44,7 @@
 from testlib import permutations, expandPermutations
 from testlib import VdsmTestCase as TestCaseBase
 from testValidation import checkSudo
-from testValidation import brokentest, stresstest
+from testValidation import stresstest
 from multiprocessing import Process
 
 EXT_SLEEP = "sleep"
@@ -86,7 +86,6 @@
         # Make sure we had the proper amount of iterations before failing
         self.assertEquals(counter[0], limit)
 
-    @brokentest("deadline is not respected")
     @MonkeyPatch(utils, 'monotonic_time', FakeTime(0))
     @MonkeyPatch(time, 'sleep', fake_sleep)
     def testTimeoutDeadlineReached(self):
@@ -104,7 +103,6 @@
                           timeout=3, sleep=1)
         self.assertEqual(utils.monotonic_time.now, 3)
 
-    @brokentest("sleep is not considered in deadline calculation")
     @MonkeyPatch(utils, 'monotonic_time', FakeTime(0))
     @MonkeyPatch(time, 'sleep', fake_sleep)
     def testTimeoutNoTimeForSleep(self):


-- 
To view, visit https://gerrit.ovirt.org/46400
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f41c6b21e3432159c13d46cfe75d1f6236cbb8c
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list