Mock time.sleep in tests to reduce test time

time.sleep() should be mocked when tests run so they don't take an
extra amount of time to run for no reason.

30s from test_health_daemon.TestHealthDaemon.test_run_sender
10s from test_rest_api_driver.TestAmphoraAPIClientTest.test_request

Change-Id: If32c2021ea37240fd200ebc41d519ed897be87b2
This commit is contained in:
Adam Harwell 2016-08-02 16:39:56 +09:00
parent 1cc2e89b2e
commit 3b11f69181
2 changed files with 5 additions and 2 deletions

View File

@ -144,13 +144,15 @@ class TestHealthDaemon(base.TestCase):
LISTENER_ID2 + '.sock'}
self.assertEqual(files, expected_files)
@mock.patch('octavia.amphorae.backends.health_daemon.'
'health_daemon.time.sleep')
@mock.patch('oslo_config.cfg.CONF.reload_config_files')
@mock.patch('octavia.amphorae.backends.health_daemon.'
'health_daemon.build_stats_message')
@mock.patch('octavia.amphorae.backends.health_daemon.'
'health_sender.UDPStatusSender')
def test_run_sender(self, mock_UDPStatusSender, mock_build_msg,
mock_reload_cfg):
mock_reload_cfg, mock_sleep):
sender_mock = mock.MagicMock()
dosend_mock = mock.MagicMock()
sender_mock.dosend = dosend_mock

View File

@ -202,7 +202,8 @@ class TestAmphoraAPIClientTest(base.TestCase):
'mac_address': FAKE_MAC_ADDRESS,
'vrrp_ip': self.amp.vrrp_ip}
def test_request(self):
@mock.patch('octavia.amphorae.drivers.haproxy.rest_api_driver.time.sleep')
def test_request(self, mock_sleep):
self.assertRaises(driver_except.TimeOutException,
self.driver.request,
'get', self.amp, 'unavailableURL')