From 9a564550eab1a4fa4f0702dd00d2400bc485b4b6 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Mon, 2 Feb 2015 17:12:27 +0100 Subject: [PATCH] Tests: Don't sleep for looping calls 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 | 5 +++++ cinder/tests/test_srb.py | 3 ++- cinder/tests/utils.py | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cinder/tests/test_emc_vnxdirect.py b/cinder/tests/test_emc_vnxdirect.py index 156e925b1..4848b7738 100644 --- a/cinder/tests/test_emc_vnxdirect.py +++ b/cinder/tests/test_emc_vnxdirect.py @@ -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)] diff --git a/cinder/tests/test_srb.py b/cinder/tests/test_srb.py index 046e5f55a..6fc2ee583 100644 --- a/cinder/tests/test_srb.py +++ b/cinder/tests/test_srb.py @@ -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 diff --git a/cinder/tests/utils.py b/cinder/tests/utils.py index 14b484081..7eee5f208 100644 --- a/cinder/tests/utils.py +++ b/cinder/tests/utils.py @@ -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) -- 2.45.2