]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix sluggish rbd unit tests
authorTom Barron <tpb@dyncloud.net>
Thu, 21 Jan 2016 16:56:14 +0000 (11:56 -0500)
committerTom Barron <tpb@dyncloud.net>
Fri, 22 Jan 2016 11:25:59 +0000 (06:25 -0500)
The rbd_test.py module tests methods decorated by utils.retry,
which does retries with exponential backoffs, without mocking out
time.sleep().

This commit mocks time.sleep(), yielding a 3x speedup, as documented
in the accompanying bug.

Closes-Bug: #1536717

Change-Id: I414629f09f397e44d3a5be794ef83658a4c1eec0

cinder/tests/unit/test_rbd.py

index a6583e4c10e089c2fe30bd9c9092ac89058c4b5a..bce0cb3c064be29638390319d8195238f332992f 100644 (file)
@@ -68,16 +68,18 @@ def common_mocks(f):
     mocks that can't/don't get unset.
     """
     def _common_inner_inner1(inst, *args, **kwargs):
+        @mock.patch('time.sleep')
         @mock.patch('cinder.volume.drivers.rbd.RBDVolumeProxy')
         @mock.patch('cinder.volume.drivers.rbd.RADOSClient')
         @mock.patch('cinder.backup.drivers.ceph.rbd')
         @mock.patch('cinder.backup.drivers.ceph.rados')
         def _common_inner_inner2(mock_rados, mock_rbd, mock_client,
-                                 mock_proxy):
+                                 mock_proxy, mock_sleep):
             inst.mock_rbd = mock_rbd
             inst.mock_rados = mock_rados
             inst.mock_client = mock_client
             inst.mock_proxy = mock_proxy
+            inst.mock_sleep = mock_sleep
             inst.mock_rbd.RBD.Error = Exception
             inst.mock_rados.Error = Exception
             inst.mock_rbd.ImageBusy = MockImageBusyException