Make sure looping calls are properly mocked

The test test_connect_volume_device_not_valid in
FibreChannelConnectorTestCase was taking over 6 seconds to complete
since the FixedIntervalLoopingCall in the method under test was not
being mocked out, making the test hang until the timeout was reached.

This fixes this and any other connector test case by moving the mocking
with a test fake into the base connector test class setUp call.

Change-Id: I6b174d94b5518d6267c1fa75528a90d95a312419
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2019-02-07 14:40:04 -06:00
parent 14be08d0b5
commit 4df3ef8f33
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
2 changed files with 9 additions and 27 deletions

View File

@ -14,36 +14,11 @@
import mock
import os
from oslo_service import loopingcall
from os_brick import exception
from os_brick.initiator.connectors import aoe
from os_brick.tests.initiator import test_connector
class FakeFixedIntervalLoopingCall(object):
def __init__(self, f=None, *args, **kw):
self.args = args
self.kw = kw
self.f = f
self._stop = False
def stop(self):
self._stop = True
def wait(self):
return self
def start(self, interval, initial_delay=None):
while not self._stop:
try:
self.f(*self.args, **self.kw)
except loopingcall.LoopingCallDone:
return self
except Exception:
raise
class AoEConnectorTestCase(test_connector.ConnectorTestCase):
"""Test cases for AoE initiator class."""
@ -52,8 +27,6 @@ class AoEConnectorTestCase(test_connector.ConnectorTestCase):
self.connector = aoe.AoEConnector('sudo')
self.connection_properties = {'target_shelf': 'fake_shelf',
'target_lun': 'fake_lun'}
self.mock_object(loopingcall, 'FixedIntervalLoopingCall',
FakeFixedIntervalLoopingCall)
def test_get_search_path(self):
expected = "/dev/etherd"

View File

@ -17,6 +17,7 @@ import sys
import mock
from oslo_concurrency import processutils as putils
from oslo_service import loopingcall
from os_brick import exception
from os_brick.initiator import connector
@ -32,6 +33,12 @@ MY_IP = '10.0.0.1'
FAKE_SCSI_WWN = '1234567890'
class ZeroIntervalLoopingCall(loopingcall.FixedIntervalLoopingCall):
def start(self, interval, initial_delay=None, stop_on_exception=True):
return super(ZeroIntervalLoopingCall, self).start(
0, 0, stop_on_exception)
class ConnectorUtilsTestCase(test_base.TestCase):
@mock.patch.object(nvme.NVMeConnector, '_get_system_uuid',
@ -126,6 +133,8 @@ class ConnectorTestCase(test_base.TestCase):
def setUp(self):
super(ConnectorTestCase, self).setUp()
self.cmds = []
self.mock_object(loopingcall, 'FixedIntervalLoopingCall',
ZeroIntervalLoopingCall)
def fake_execute(self, *cmd, **kwargs):
self.cmds.append(" ".join(cmd))