Speed up irmc power unit tests

Some iRMC unit tests were mocking the wrong sleep() method, resulting
in the tests each taking over 2 seconds to complete. This fixes it by
mocking eventlet.greenthread.sleep instead, which is what is actually
being called. With these changes, the unit tests take under 0.5
seconds (your mileage may vary).

Change-Id: Ia1227751f6c3ecf906ec078d1dd07a3adba1d044
This commit is contained in:
Ruby Loo 2017-02-02 23:01:55 +00:00
parent ac2b1a48ef
commit fa4a5a59b2

View File

@ -16,8 +16,6 @@
Test class for iRMC Power Driver
"""
import time
import mock
from oslo_utils import uuidutils
@ -68,7 +66,7 @@ class IRMCPowerInternalMethodsTestCase(db_base.DbTestCase):
self.assertFalse(irmc_power._is_expected_power_state(
target_state, boot_status_value))
@mock.patch.object(time, 'sleep', lambda seconds: None)
@mock.patch('eventlet.greenthread.sleep', lambda n: None)
@mock.patch('ironic.drivers.modules.irmc.power.snmp.SNMPClient',
spec_set=True, autospec=True)
def test__wait_power_state_soft_power_off(self, snmpclient_mock):
@ -87,7 +85,7 @@ class IRMCPowerInternalMethodsTestCase(db_base.DbTestCase):
self.assertEqual(states.POWER_OFF, task.node.power_state)
self.assertEqual(states.NOSTATE, task.node.target_power_state)
@mock.patch.object(time, 'sleep', lambda seconds: None)
@mock.patch('eventlet.greenthread.sleep', lambda n: None)
@mock.patch('ironic.drivers.modules.irmc.power.snmp.SNMPClient',
spec_set=True, autospec=True)
def test__wait_power_state_soft_reboot(self, snmpclient_mock):
@ -106,7 +104,7 @@ class IRMCPowerInternalMethodsTestCase(db_base.DbTestCase):
self.assertEqual(states.POWER_ON, task.node.power_state)
self.assertEqual(states.NOSTATE, task.node.target_power_state)
@mock.patch.object(time, 'sleep', lambda seconds: None)
@mock.patch('eventlet.greenthread.sleep', lambda n: None)
@mock.patch('ironic.drivers.modules.irmc.power.snmp.SNMPClient',
spec_set=True, autospec=True)
def test__wait_power_state_timeout(self, snmpclient_mock):