From c10f5c2cd0d85e5ad496cbf59f7804f894b52c0c Mon Sep 17 00:00:00 2001 From: Tom Barron Date: Mon, 7 Mar 2016 15:05:21 -0500 Subject: [PATCH] Trim 5s+ from storwize unit tests The test test_run_ssh_fail_to_secondary_ip test case in the StorWize Driver does a greenthread.sleep(random.randint()) inside a retry loop. Its execution time often approaches 5s. This commit mocks random.randint() in this test so that the greenthread.sleep() duration is always zero, reducing execution time for the test to under half a second. The various test_storwize_consistency_group* tests trigger FixedIntervalLoopingCalls. Mocking them with ZeroIntervalLoopingCalls reduces their total execution time from about 8s to under 3s. We also fix the fake user and project ids in this file so that it no longer emits FutureWarnings from oslo.versionedobjects about invalid uuids as documented here [1]. [1] http://docs.openstack.org/developer/oslo.versionedobjects/api/fields.html#oslo_versionedobjects.fields.UUIDField Change-Id: I05dc3c4a5a886ce323430055f34d6c578c0f4443 --- cinder/tests/unit/test_storwize_svc.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cinder/tests/unit/test_storwize_svc.py b/cinder/tests/unit/test_storwize_svc.py index 492e2a8b2..d4e77dc6a 100644 --- a/cinder/tests/unit/test_storwize_svc.py +++ b/cinder/tests/unit/test_storwize_svc.py @@ -36,6 +36,7 @@ from cinder.i18n import _ from cinder.objects import fields from cinder import ssh_utils from cinder import test +from cinder.tests.unit import fake_constants as fake from cinder.tests.unit import utils as testutils from cinder import utils from cinder.volume import configuration as conf @@ -2723,6 +2724,7 @@ class StorwizeSVCCommonDriverTestCase(test.TestCase): min_size=self._driver.configuration.ssh_min_pool_conn, max_size=self._driver.configuration.ssh_max_pool_conn) + @mock.patch.object(random, 'randint', mock.Mock(return_value=0)) @mock.patch.object(ssh_utils, 'SSHPool') @mock.patch.object(processutils, 'ssh_execute') def test_run_ssh_fail_to_secondary_ip(self, mock_ssh_execute, @@ -4009,10 +4011,12 @@ class StorwizeSVCCommonDriverTestCase(test.TestCase): self.assertIs('copying', model_update['replication_status']) self.driver.delete_volume(volume) + @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', + new=testutils.ZeroIntervalLoopingCall) def test_storwize_consistency_group_snapshot(self): cg_type = self._create_consistency_group_volume_type() - self.ctxt.user_id = 'fake_user_id' - self.ctxt.project_id = 'fake_project_id' + self.ctxt.user_id = fake.user_id + self.ctxt.project_id = fake.project_id cg = self._create_consistencygroup_in_db(volume_type_id=cg_type['id']) model_update = self.driver.create_consistencygroup(self.ctxt, cg) @@ -4045,11 +4049,13 @@ class StorwizeSVCCommonDriverTestCase(test.TestCase): for volume in model_update[1]: self.assertEqual('deleted', volume['status']) + @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', + new=testutils.ZeroIntervalLoopingCall) def test_storwize_consistency_group_from_src_invalid(self): # Invalid input case for create cg from src cg_type = self._create_consistency_group_volume_type() - self.ctxt.user_id = 'fake_user_id' - self.ctxt.project_id = 'fake_project_id' + self.ctxt.user_id = fake.user_id + self.ctxt.project_id = fake.project_id # create cg in db cg = self._create_consistencygroup_in_db(volume_type_id=cg_type['id']) @@ -4123,11 +4129,13 @@ class StorwizeSVCCommonDriverTestCase(test.TestCase): for volume in model_update[1]: self.assertEqual('deleted', volume['status']) + @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', + new=testutils.ZeroIntervalLoopingCall) def test_storwize_consistency_group_from_src(self): # Valid case for create cg from src cg_type = self._create_consistency_group_volume_type() - self.ctxt.user_id = 'fake_user_id' - self.ctxt.project_id = 'fake_project_id' + self.ctxt.user_id = fake.user_id + self.ctxt.project_id = fake.project_id pool = _get_test_pool() # Create cg in db cg = self._create_consistencygroup_in_db(volume_type_id=cg_type['id']) -- 2.45.2