]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Tests: Don't sleep for looping calls
authorEric Harney <eharney@redhat.com>
Mon, 2 Feb 2015 16:12:27 +0000 (17:12 +0100)
committerEric Harney <eharney@redhat.com>
Mon, 2 Feb 2015 16:38:09 +0000 (17:38 +0100)
Some tests are sleeping for a few seconds when
running looping calls.  Mock this out so that
tests do not take longer than required to run.

This takes running vnxdirect and srb tests from:
Ran 105 tests in 37.876s
 to:
Ran 105 tests in 23.154s

Change-Id: I1e79c04d83a59ab37d7550b0021a67fe61e8096e

cinder/tests/test_emc_vnxdirect.py
cinder/tests/test_srb.py
cinder/tests/utils.py

index 156e925b17a4bc4056de1a9e284975fdc73c6e8a..4848b773863a3663c74f78c20f2f5b20920b0228 100644 (file)
@@ -21,6 +21,7 @@ from oslo_concurrency import processutils
 
 from cinder import exception
 from cinder import test
+from cinder.tests.utils import ZeroIntervalLoopingCall
 from cinder.volume import configuration as conf
 from cinder.volume.drivers.emc.emc_cli_fc import EMCCLIFCDriver
 from cinder.volume.drivers.emc.emc_cli_iscsi import EMCCLIISCSIDriver
@@ -1340,6 +1341,8 @@ Time Remaining:  0 second(s)
             mock.call('lun', '-list', '-name', 'vol2', '-attachedSnapshot')]
         fake_cli.assert_has_calls(expect_cmd)
 
+    @mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall',
+                new=ZeroIntervalLoopingCall)
     def test_create_volume_from_snapshot_sync_failed(self):
 
         output_smp = ("""LOGICAL UNIT NUMBER 1
@@ -1460,6 +1463,8 @@ Time Remaining:  0 second(s)
         expected = [mock.call(*self.testData.LUN_EXTEND_CMD('failed_vol1', 2))]
         fake_cli.assert_has_calls(expected)
 
+    @mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall',
+                new=ZeroIntervalLoopingCall)
     def test_extend_volume_failed(self):
         commands = [self.testData.LUN_PROPERTY_ALL_CMD('failed_vol1')]
         results = [self.testData.LUN_PROPERTY('failed_vol1', size=2)]
index 046e5f55af0f430ebcbf8ec4a9f6fce03c54c59a..6fc2ee5833b7bd4876cfedb8717b753645680241 100644 (file)
@@ -173,7 +173,8 @@ class SRBRetryTestCase(test.TestCase):
 
     def test_retry_fail_and_succeed_mixed(self):
 
-        @srb.retry(count=4, exceptions=(Exception))
+        @srb.retry(count=4, exceptions=(Exception),
+                   sleep_mechanism=srb.retry.SLEEP_NONE)
         def _try_failing(self):
             attempted = self.attempts
             self.attempts = self.attempts + 1
index 14b484081f76c1945f01d324cf8b6c2fe6b0fa02..7eee5f2081362ad7cc622583316a86dd884b340c 100644 (file)
@@ -13,9 +13,9 @@
 #    under the License.
 #
 
-
 from cinder import context
 from cinder import db
+from cinder.openstack.common import loopingcall
 
 
 def get_test_admin_context():
@@ -121,3 +121,9 @@ def create_cgsnapshot(ctxt,
     for key in kwargs:
         cgsnap[key] = kwargs[key]
     return db.cgsnapshot_create(ctxt, cgsnap)
+
+
+class ZeroIntervalLoopingCall(loopingcall.FixedIntervalLoopingCall):
+    def start(self, interval, **kwargs):
+        kwargs['initial_delay'] = 0
+        return super(ZeroIntervalLoopingCall, self).start(0, **kwargs)