]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fake out sleeps in unit tests
authorJohn Griffith <john.griffith8@gmail.com>
Fri, 1 May 2015 16:35:30 +0000 (10:35 -0600)
committerJohn Griffith <john.griffith8@gmail.com>
Fri, 1 May 2015 21:38:34 +0000 (15:38 -0600)
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

cinder/tests/unit/brick/test_brick_linuxscsi.py
cinder/tests/unit/integrated/test_extensions.py
cinder/tests/unit/test_volume.py
cinder/tests/unit/test_xio.py

index 0b3e35baccb7b95c745fc39e722ccfd6144ba898..4225799aef9fbf68493cee8be8d4da4d5d5cdc17 100644 (file)
@@ -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)
index 9bcab2642680e59568649601d99ecc50b9f07051..e1e6d03add00dae2ef14ef374f0bf4fc5a029515 100644 (file)
@@ -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)
index 8debdf55aeb258b14434fd854997be35b844148a..2c7b129ed39967e6b1d9730a15cc916d07d1bc92 100644 (file)
@@ -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
index 7ad0cd889c244d7985a68d2ccb42845bfece37f8..9553e346adee1f1e8085f26fc19dbfc7c33a7661 100644 (file)
@@ -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",