diff options
author | Ross Brattain <ross.b.brattain@intel.com> | 2017-09-03 17:20:41 -0700 |
---|---|---|
committer | Ross Brattain <ross.b.brattain@intel.com> | 2017-09-03 17:22:47 -0700 |
commit | ca12137494ee4edadd77e1e4e0fb86d297a37fe3 (patch) | |
tree | 4636b8e3dc556325e1dd2fd4e644028643af1adc /tests | |
parent | c19115bafe0141326b189f317a684bf4681c8bd0 (diff) |
test_vsperf_dpdk: mock time to speedup unitests
If you put time.sleep(1) all over your code you need
to mock time.sleep() in your unittests lest the unittests
take forever.
Change-Id: I9ebbf9e21c98e8c46bab727bbb22f33045db4361
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py index de5bae2f3..5759f0a90 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py +++ b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py @@ -118,7 +118,8 @@ class VsperfDPDKTestCase(unittest.TestCase): result = p._is_dpdk_setup() self.assertEqual(result, True) - def test_vsperf_dpdk_dpdk_setup_first(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_dpdk_setup_first(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks @@ -135,42 +136,43 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertEqual(p._is_dpdk_setup(), False) self.assertEqual(p.dpdk_setup_done, True) - def test_vsperf_dpdk_dpdk_setup_next(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_dpdk_setup_next(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) - # dpdk_setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - p.dpdk_setup() self.assertEqual(p._is_dpdk_setup(), True) self.assertEqual(p.dpdk_setup_done, True) - def test_vsperf_dpdk_dpdk_setup_fail(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_dpdk_setup_fail(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) - - # dpdk_setup() specific mocks mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + self.assertEqual(p.setup_done, True) self.assertRaises(RuntimeError, p.dpdk_setup) - def test_vsperf_dpdk_run_ok(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_run_ok(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() @@ -179,7 +181,6 @@ class VsperfDPDKTestCase(unittest.TestCase): # run() specific mocks mock_subprocess.call().execute.return_value = None - mock_subprocess.call().execute.return_value = None mock_ssh.SSH.from_node().execute.return_value = ( 0, 'throughput_rx_fps\r\n14797660.000\r\n', '') @@ -193,6 +194,7 @@ class VsperfDPDKTestCase(unittest.TestCase): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() @@ -211,6 +213,7 @@ class VsperfDPDKTestCase(unittest.TestCase): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() |