Mock time.sleep in slow tests 79/66779/3
authorEmma Foley <emma.l.foley@intel.com>
Tue, 29 Jan 2019 18:15:23 +0000 (18:15 +0000)
committerEmma Foley <emma.l.foley@intel.com>
Thu, 31 Jan 2019 12:09:32 +0000 (12:09 +0000)
time.sleep was called in a number of classes which wasn't
mocked in the tests.
This accounted for 2.5 minutes of UT execution time.

The calls to time.sleep() have been mocked, and the test
execution time has been reduced.

JIRA: YARDSTICK-1595
Change-Id: I0a4f4962513cf8845471b074347601e33b35ef25
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py
yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py
yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py

index 59f37be..1a99479 100644 (file)
@@ -11,6 +11,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+import time
 
 import unittest
 import mock
@@ -28,7 +29,8 @@ class TestProxIrqProfile(unittest.TestCase):
     def _stop_mocks(self):
         self._mock_log_info.stop()
 
-    def test_execute_1(self):
+    @mock.patch.object(time, 'sleep')
+    def test_execute_1(self, *args):
         tp_config = {
             'traffic_profile': {
             },
index 11bee03..2660d41 100644 (file)
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+import time
 
 import unittest
 import mock
@@ -78,7 +79,8 @@ class TestProxProfile(unittest.TestCase):
         profile.init(queue)
         self.assertIs(profile.queue, queue)
 
-    def test_execute_traffic(self):
+    @mock.patch.object(time, 'sleep')
+    def test_execute_traffic(self, *args):
         packet_sizes = [
             10,
             100,
index 9a30fb9..742dbfe 100644 (file)
@@ -2400,6 +2400,7 @@ class TestProxProfileHelper(unittest.TestCase):
         with helper.traffic_context(64, 1):
             pass
 
+    @mock.patch.object(time, 'sleep')
     def test_run_test(self, *args):
         resource_helper = mock.MagicMock()
         resource_helper.step_delta = 0.4
@@ -2549,6 +2550,7 @@ class TestProxBngProfileHelper(unittest.TestCase):
         self.assertEqual(helper.arp_task_cores, expected_arp_task)
         self.assertEqual(helper._cores_tuple, expected_combined)
 
+    @mock.patch.object(time, 'sleep')
     def test_run_test(self, *args):
         resource_helper = mock.MagicMock()
         resource_helper.step_delta = 0.4
@@ -2675,6 +2677,7 @@ class TestProxVpeProfileHelper(unittest.TestCase):
         self.assertEqual(helper.inet_ports, expected_inet)
         self.assertEqual(helper._ports_tuple, expected_combined)
 
+    @mock.patch.object(time, 'sleep')
     def test_run_test(self, *args):
         resource_helper = mock.MagicMock()
         resource_helper.step_delta = 0.4
@@ -2792,6 +2795,7 @@ class TestProxlwAFTRProfileHelper(unittest.TestCase):
         self.assertEqual(helper.inet_ports, expected_inet)
         self.assertEqual(helper._ports_tuple, expected_combined)
 
+    @mock.patch.object(time, 'sleep')
     def test_run_test(self, *args):
         resource_helper = mock.MagicMock()
         resource_helper.step_delta = 0.4
index a5b9f25..a390ed0 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2016-2017 Intel Corporation
+# Copyright (c) 2016-2018 Intel Corporation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -11,6 +11,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+import time
 
 import mock
 import unittest
@@ -24,7 +25,8 @@ from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
 
 class TestTrexRfcResouceHelper(unittest.TestCase):
 
-    def test__run_traffic_once(self):
+    @mock.patch.object(time, 'sleep')
+    def test__run_traffic_once(self, *args):
         mock_setup_helper = mock.Mock()
         mock_traffic_profile = mock.Mock()
         mock_traffic_profile.config.duration = 3