]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix laggard cisco FC zone client unit tests
authorTom Barron <tpb@dyncloud.net>
Thu, 21 Jan 2016 03:44:48 +0000 (22:44 -0500)
committerTom Barron <tpb@dyncloud.net>
Fri, 22 Jan 2016 11:45:40 +0000 (06:45 -0500)
The test_cisco_fc_zone_client_cli.py unit module tests methods
decorated by utils.retry, which does retries with exponential
backoffs, without mocking out time.sleep().  One test in this
suite takes about 10% of the total time to run all cinder unit
tests.

This commit mocks time.sleep() in two critical tests in this
module, yielding a 30x speedup in run-time for the module.

Closes-Bug: #1536457

Change-Id: I3a686b760e2049a1f0ae4f8ee5ccbb4fa974aa1f

cinder/tests/unit/zonemanager/test_cisco_fc_zone_client_cli.py

index c5c057c3253069ad95da79cf7f6ecc69c24060a2..b3e155ed53fb633a25bee48916c93b28b5f3bbf1 100644 (file)
@@ -17,6 +17,8 @@
 
 """Unit tests for Cisco fc zone client cli."""
 
+import time
+
 import mock
 from oslo_concurrency import processutils
 from six.moves import range
@@ -196,7 +198,8 @@ class TestCiscoFCZoneClientCLI(cli.CiscoFCZoneClientCLI, test.TestCase):
         run_ssh_mock.assert_called_once_with(cmd_list, True)
 
     @mock.patch.object(cli.CiscoFCZoneClientCLI, '_run_ssh')
-    def test__cfg_save_with_retry(self, run_ssh_mock):
+    @mock.patch.object(time, 'sleep')
+    def test__cfg_save_with_retry(self, mock_sleep, run_ssh_mock):
         cmd_list = ['copy', 'running-config', 'startup-config']
         run_ssh_mock.side_effect = [
             processutils.ProcessExecutionError,
@@ -212,7 +215,8 @@ class TestCiscoFCZoneClientCLI(cli.CiscoFCZoneClientCLI, test.TestCase):
         ])
 
     @mock.patch.object(cli.CiscoFCZoneClientCLI, '_run_ssh')
-    def test__cfg_save_with_error(self, run_ssh_mock):
+    @mock.patch.object(time, 'sleep')
+    def test__cfg_save_with_error(self, mock_sleep, run_ssh_mock):
         cmd_list = ['copy', 'running-config', 'startup-config']
         run_ssh_mock.side_effect = processutils.ProcessExecutionError