]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Tests: Don't sleep for looping calls (eqlx)
authorEric Harney <eharney@redhat.com>
Tue, 3 Feb 2015 11:16:08 +0000 (12:16 +0100)
committerEric Harney <eharney@redhat.com>
Tue, 3 Feb 2015 11:26:48 +0000 (12:26 +0100)
Mock out greenthread.sleep() so that unit tests
do not spend extra time sleeping.

This changes the eqlx tests from:
Ran 23 tests in 33.533s
 to:
Ran 23 tests in 19.260s

Also remove unneeded randomness.

Change-Id: I1cc03f41fa41e827ec5e39b28a49f6a9ad66b2a1

cinder/tests/test_eqlx.py

index c63935db2ec9b21e65123c9b4b638fb10193a106..546d8b355e1410894f13acd093d82393c0417ecf 100644 (file)
@@ -13,9 +13,9 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import random
 import time
 
+from eventlet import greenthread
 import mock
 import mox
 from oslo_concurrency import processutils
@@ -324,8 +324,9 @@ class DellEQLSanISCSIDriverTestCase(test.TestCase):
         self.assertRaises(processutils.ProcessExecutionError,
                           self.driver._ssh_execute, ssh, cmd)
 
-    def test_ensure_retries(self):
-        num_attempts = random.randint(1, 5)
+    @mock.patch.object(greenthread, 'sleep')
+    def test_ensure_retries(self, _gt_sleep):
+        num_attempts = 3
         self.driver.configuration.eqlx_cli_max_retries = num_attempts
 
         self.mock_object(self.driver, '_ssh_execute',
@@ -348,9 +349,9 @@ class DellEQLSanISCSIDriverTestCase(test.TestCase):
         self.assertEqual(num_attempts + 1,
                          self.driver._ssh_execute.call_count)
 
-    def test_ensure_retries_on_channel_timeout(self):
-
-        num_attempts = random.randint(1, 5)
+    @mock.patch.object(greenthread, 'sleep')
+    def test_ensure_retries_on_channel_timeout(self, _gt_sleep):
+        num_attempts = 3
         self.driver.configuration.eqlx_cli_max_retries = num_attempts
 
         # mocks for calls and objects in _run_ssh