From 3f70f6f34fdea1706d92a3af4a4b828e9451f7dc Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Tue, 3 Feb 2015 12:16:08 +0100 Subject: [PATCH] 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 --- cinder/tests/test_eqlx.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 -- 2.45.2