From: John Griffith Date: Fri, 1 May 2015 16:35:30 +0000 (-0600) Subject: Fake out sleeps in unit tests X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=85b9a70a419122d6586d1547dba2a67e84690d30;p=openstack-build%2Fcinder-build.git Fake out sleeps in unit tests Just a minor cleanup, had a few tests that were doing sleeps (or looping calls for those that prefer it) that were being executed to test timeouts in the unit tests. No value in actually *waiting* for these, so this patch just mocks them out so we still test the procedure but don't actually have to wait. This shaves about 30 seconds or so off of the unit test run, not a huge deal, but every little bit helps IMO. Also noticed a LOG.debug message in the test_extensions file that wasn't picked up in other cleanup work so I removed that debug log call as well. Change-Id: I415ac75816e8a0f4c48c61b23391df1a9a016d62 --- diff --git a/cinder/tests/unit/brick/test_brick_linuxscsi.py b/cinder/tests/unit/brick/test_brick_linuxscsi.py index 0b3e35bac..4225799ae 100644 --- a/cinder/tests/unit/brick/test_brick_linuxscsi.py +++ b/cinder/tests/unit/brick/test_brick_linuxscsi.py @@ -16,11 +16,13 @@ import os import os.path import string +import mock from oslo_log import log as logging from cinder.brick import exception from cinder.brick.initiator import linuxscsi from cinder import test +from cinder.tests.unit import utils LOG = logging.getLogger(__name__) @@ -68,6 +70,8 @@ class LinuxSCSITestCase(test.TestCase): ('tee -a /sys/block/sdc/device/delete')] self.assertEqual(expected_commands, self.cmds) + @mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall', + new=utils.ZeroIntervalLoopingCall) def test_wait_for_volume_removal(self): fake_path = '/dev/disk/by-path/fake-iscsi-iqn-lun-0' self.stubs.Set(os.path, "exists", lambda x: True) diff --git a/cinder/tests/unit/integrated/test_extensions.py b/cinder/tests/unit/integrated/test_extensions.py index 9bcab2642..e1e6d03ad 100644 --- a/cinder/tests/unit/integrated/test_extensions.py +++ b/cinder/tests/unit/integrated/test_extensions.py @@ -37,5 +37,4 @@ class ExtensionsTest(integrated_helpers._IntegratedTestBase): """Simple check that fox-n-socks works.""" response = self.api.api_request('/foxnsocks') foxnsocks = response.text - LOG.debug("foxnsocks: %s" % foxnsocks) self.assertEqual('Try to say this Mr. Knox, sir...', foxnsocks) diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index 8debdf55a..2c7b129ed 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -24,6 +24,7 @@ import shutil import socket import sys import tempfile +import time import eventlet import mock @@ -39,7 +40,7 @@ from taskflow.engines.action_engine import engine from cinder.backup import driver as backup_driver from cinder.brick.local_dev import lvm as brick_lvm -from cinder import compute +from cinder.compute import nova from cinder import context from cinder import db from cinder import exception @@ -2632,6 +2633,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertNotIn(iscsi_target, targets) targets.append(iscsi_target) + # FIXME(jdg): What is this actually testing? + # We never call the internal _check method? for _index in xrange(100): tests_utils.create_volume(self.context, **self.volume_params) for volume_id in volume_ids: @@ -3818,7 +3821,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertIsNone(volume['migration_status']) self.assertEqual('available', volume['status']) - @mock.patch.object(compute.nova.API, 'update_server_volume') + @mock.patch.object(nova.API, 'update_server_volume') @mock.patch('cinder.volume.manager.VolumeManager.' 'migrate_volume_completion') @mock.patch('cinder.db.volume_get') @@ -3843,7 +3846,7 @@ class VolumeTestCase(BaseVolumeTestCase): fake_new_volume['id'], error=False) - @mock.patch.object(compute.nova.API, 'update_server_volume') + @mock.patch.object(nova.API, 'update_server_volume') @mock.patch('cinder.volume.manager.VolumeManager.' 'migrate_volume_completion') @mock.patch('cinder.db.volume_get') @@ -4020,7 +4023,8 @@ class VolumeTestCase(BaseVolumeTestCase): mock.patch.object(volume_rpcapi.VolumeAPI, 'create_volume') as \ mock_create_volume, \ mock.patch.object(self.volume, '_clean_temporary_volume') as \ - clean_temporary_volume: + clean_temporary_volume, \ + mock.patch.object(time, 'sleep'): # Exception case at the timeout of the volume creation mock_create_volume.side_effect = fake_create_volume diff --git a/cinder/tests/unit/test_xio.py b/cinder/tests/unit/test_xio.py index 7ad0cd889..9553e346a 100644 --- a/cinder/tests/unit/test_xio.py +++ b/cinder/tests/unit/test_xio.py @@ -19,6 +19,7 @@ from oslo_log import log as logging from cinder import context from cinder import exception from cinder import test +from cinder.tests.unit import utils from cinder.volume.drivers import xio from cinder.volume import qos_specs from cinder.volume import volume_types @@ -1194,6 +1195,8 @@ class XIOISEDriverTestCase(object): self.setup_driver() self.driver.create_snapshot(SNAPSHOT1) + @mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall', + new=utils.ZeroIntervalLoopingCall) def test_negative_create_snapshot_invalid_state_recover(self, mock_req): ctxt = context.get_admin_context() extra_specs = {"Feature:Pool": "1", @@ -1218,6 +1221,8 @@ class XIOISEDriverTestCase(object): self.setup_driver() self.driver.create_snapshot(SNAPSHOT1) + @mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall', + new=utils.ZeroIntervalLoopingCall) def test_negative_create_snapshot_invalid_state_norecover(self, mock_req): ctxt = context.get_admin_context() extra_specs = {"Feature:Pool": "1",