From: Eric Harney Date: Tue, 3 Feb 2015 11:16:08 +0000 (+0100) Subject: Tests: Don't sleep for looping calls (eqlx) X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3f70f6f34fdea1706d92a3af4a4b828e9451f7dc;p=openstack-build%2Fcinder-build.git Tests: Don't sleep for looping calls (eqlx) 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 --- diff --git a/cinder/tests/test_eqlx.py b/cinder/tests/test_eqlx.py index c63935db2..546d8b355 100644 --- a/cinder/tests/test_eqlx.py +++ b/cinder/tests/test_eqlx.py @@ -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