Change in vdsm[master]: tests: Fix RescanTimeoutsTests
nsoffer at redhat.com
nsoffer at redhat.com
Tue Mar 31 23:42:08 UTC 2015
Nir Soffer has uploaded a new change for review.
Change subject: tests: Fix RescanTimeoutsTests
......................................................................
tests: Fix RescanTimeoutsTests
In commit 4c10d3d10c (multipath: Wait for udev events after rescan) I
removed unneeded and badly implemented minimal timeout, and the unneeded
optional arguments in iscsi.rescan() but forgot to update the tests.
In this patch:
- remove the now unneeded and broken test for minimal timeout
(the test was passing while the code was broken)
- simplify the testing infrastructure
- instead of passing arguments to rescan, monkey-patch the config.
- use safe monkey-patching.
- use monotonic_time
- use real process so we get SIGCHLD when the scan is finished;
otherwise, the tests may pass while the code is broken
- add test for normal operation
Change-Id: I308c73eb7059053aa91bf15957cf9029234b37d1
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/iscsiTests.py
1 file changed, 23 insertions(+), 60 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/22/39422/1
diff --git a/tests/iscsiTests.py b/tests/iscsiTests.py
index 80693bd..95e3af4 100644
--- a/tests/iscsiTests.py
+++ b/tests/iscsiTests.py
@@ -1,84 +1,47 @@
import os
-import threading
-import time
from contextlib import contextmanager
+from monkeypatch import MonkeyPatch
from testlib import VdsmTestCase as TestCaseBase
+from testlib import make_config
+
+from vdsm import utils
from storage import iscsi
+from storage import iscsiadm
-class AsyncStubOperation(object):
- def __init__(self, timeout):
- self._evt = threading.Event()
- if timeout == 0:
- self._evt.set()
- else:
- threading.Timer(timeout, self._evt.set)
-
- def wait(self, timeout=None, cond=None):
- if cond is not None:
- raise Exception("TODO!!!")
-
- self._evt.wait(timeout)
-
- def stop(self):
- self._evt.set()
-
- def result(self):
- if self._evt.is_set():
- return (None, None)
- else:
- return None
+def fake_rescan(timeout):
+ def func():
+ proc = utils.execCmd(["sleep", str(timeout)], sync=False)
+ return utils.AsyncProcessOperation(proc)
+ return func
class RescanTimeoutTests(TestCaseBase):
- def setUp(self):
- self._iscsiadm_rescan_async = \
- iscsi.iscsiadm.session_rescan_async
- iscsi.iscsiadm.session_rescan_async = self._iscsi_stub
- self._timeout = 0
-
- def tearDown(self):
- iscsi.iscsiadm.session_rescan_async = \
- self._iscsiadm_rescan_async
-
- def _iscsi_stub(self):
- return AsyncStubOperation(self._timeout)
@contextmanager
def assertMaxDuration(self, maxtime):
- start = time.time()
+ start = utils.monotonic_time()
try:
yield
finally:
- end = time.time()
- elapsed = end - start
+ elapsed = utils.monotonic_time() - start
if maxtime < elapsed:
- self.fail("Operation was too slow %fs > %fs" %
+ self.fail("Operation was too slow %.2fs > %.2fs" %
(elapsed, maxtime))
- @contextmanager
- def assertMinDuration(self, mintime):
- start = time.time()
- try:
- yield
- finally:
- end = time.time()
- elapsed = end - start
- if mintime > elapsed:
- self.fail("Operation was too fast %fs > %fs" %
- (elapsed, mintime))
+ @MonkeyPatch(iscsiadm, 'session_rescan_async', fake_rescan(0.1))
+ def testWait(self):
+ with self.assertMaxDuration(0.3):
+ iscsi.rescan()
- def testFast(self):
- self._timeout = 0
- with self.assertMinDuration(2):
- iscsi.rescan(2, 4)
-
- def testSlow(self):
- self._timeout = 60
- with self.assertMaxDuration(3):
- iscsi.rescan(1, 2)
+ @MonkeyPatch(iscsiadm, 'session_rescan_async', fake_rescan(2))
+ @MonkeyPatch(iscsi, 'config',
+ make_config([("irs", "scsi_rescan_maximal_timeout", "1")]))
+ def testTimeout(self):
+ with self.assertMaxDuration(1.2):
+ iscsi.rescan()
class IscsiAdmTests(TestCaseBase):
--
To view, visit https://gerrit.ovirt.org/39422
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I308c73eb7059053aa91bf15957cf9029234b37d1
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