Fix slow unit tests

As of liberty.2, the Manila unit tests are taking ~60 seconds to run
on my system. A dozen or so of the tests consistently take an integral
number of seconds to run (i.e. 1, 2, 3 or 4 seconds), indicating the
presence of a time.sleep() call in the code that hasn't been mocked.
By mocking time.sleep() and time.time() in just a few files, the time
needed to run the unit tests falls by a third to ~40 seconds (!).

Change-Id: I66a6d864823b10a4193eadf65a1c5d3028f2afa7
Closes-bug: 1478644
This commit is contained in:
Clinton Knight 2015-07-27 13:06:57 -04:00
parent 533c21129a
commit 0a39557c74
4 changed files with 8 additions and 2 deletions

View File

@ -62,6 +62,7 @@ class SopShareDriverTestCase(test.TestCase):
self._driver = sop.SopShareDriver(configuration=self.fake_conf)
self.share = fake_share.fake_share(share_proto='NFS')
self._driver.share_backend_name = 'HDS_SOP'
self.mock_object(time, 'sleep')
def test_add_file_system_sopapi(self):
httpclient = httplib2.Http(disable_ssl_certificate_validation=True,

View File

@ -17,6 +17,7 @@ import httplib
import socket
import ssl
import tempfile
import time
import mock
from oslo_serialization import jsonutils
@ -112,6 +113,7 @@ class QuobyteJsonRpcTestCase(test.TestCase):
self.rpc = jsonrpc.JsonRpc(url="http://test",
user_credentials=("me", "team"))
self.mock_object(self.rpc, '_connection')
self.mock_object(time, 'sleep')
def test_request_generation_and_basic_auth(self):
self.mock_object(

View File

@ -124,6 +124,7 @@ class GenericShareDriverTestCase(test.TestCase):
}
self.access = fake_share.fake_access()
self.snapshot = fake_share.fake_snapshot()
self.mock_object(time, 'sleep')
def test_do_setup(self):
self.mock_object(volume, 'API')
@ -296,7 +297,6 @@ class GenericShareDriverTestCase(test.TestCase):
mock.Mock(return_value=mount_path))
self.mock_object(self._driver, '_ssh_exec',
mock.Mock(side_effect=_side_effect))
self.mock_object(time, 'sleep')
self._driver._unmount_device(self.share, self.server)
@ -720,6 +720,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_wait_for_available_volume_invalid(self, volume_get_mock):
fake_volume = {'status': 'creating', 'id': 'fake'}
self.mock_object(self._driver.volume_api, 'get', volume_get_mock)
self.mock_object(time, 'time',
mock.Mock(side_effect=[1.0, 1.33, 1.67, 2.0]))
self.assertRaises(
exception.ManilaException,

View File

@ -17,6 +17,7 @@
"""Unit tests for the instance module."""
import os
import time
import ddt
import mock
@ -130,6 +131,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
mock.Mock(side_effect=FakeNetworkHelper))
self._manager = service_instance.ServiceInstanceManager(self.config)
self._manager._execute = mock.Mock(return_value=('', ''))
self.mock_object(time, 'sleep')
def test_get_config_option_from_driver_config(self):
username1 = 'fake_username_1_%s' % self.id()
@ -1184,7 +1186,6 @@ class ServiceInstanceManagerTestCase(test.TestCase):
self._manager.compute_api.server_get.assert_called_once_with(
self._manager.admin_context, server_create['id'])
self.assertTrue(service_instance.time.sleep.called)
self.assertTrue(service_instance.time.sleep.called)
@ddt.data(
dict(name=None, path=None),