]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use FakeLoopingCall instead of the real one
authorNikolay Sobolevskiy <nsobolevsky@mirantis.com>
Mon, 19 Aug 2013 07:48:03 +0000 (11:48 +0400)
committerNikolay Sobolevskiy <nsobolevsky@mirantis.com>
Mon, 19 Aug 2013 07:48:03 +0000 (11:48 +0400)
Decrease the execution time in brick's tests.

Change-Id: Idef19e91f593c2c276015d5bf9f9cc85cd6094ad

cinder/tests/brick/test_brick_connector.py

index 5ec9e657eff5c1fcd05adbeb11b1b7a3a45e2eea..fe8d44b3d9b40c3bda4ed55a5b76dcface8f39f0 100644 (file)
@@ -26,6 +26,7 @@ from cinder.brick.initiator import host_driver
 from cinder.brick.initiator import linuxfc
 from cinder.brick.initiator import linuxscsi
 from cinder.openstack.common import log as logging
+from cinder.openstack.common import loopingcall
 from cinder.openstack.common import processutils as putils
 from cinder import test
 
@@ -330,6 +331,30 @@ class FibreChannelConnectorTestCase(ConnectorTestCase):
                           connection_info['data'])
 
 
+class FakeFixedIntervalLoopingCall(object):
+    def __init__(self, f=None, *args, **kw):
+        self.args = args
+        self.kw = kw
+        self.f = f
+        self._stop = False
+
+    def stop(self):
+        self._stop = True
+
+    def wait(self):
+        return self
+
+    def start(self, interval, initial_delay=None):
+        while not self._stop:
+            try:
+                self.f(*self.args, **self.kw)
+            except loopingcall.LoopingCallDone:
+                return self
+            except Exception:
+                LOG.exception(_('in fixed duration looping call'))
+                raise
+
+
 class AoEConnectorTestCase(ConnectorTestCase):
     """Test cases for AoE initiator class."""
     def setUp(self):
@@ -338,6 +363,9 @@ class AoEConnectorTestCase(ConnectorTestCase):
         self.connector = connector.AoEConnector()
         self.connection_properties = {'target_shelf': 'fake_shelf',
                                       'target_lun': 'fake_lun'}
+        self.stubs.Set(loopingcall,
+                       'FixedIntervalLoopingCall',
+                       FakeFixedIntervalLoopingCall)
 
     def tearDown(self):
         self.mox.VerifyAll()