Merge "Veritas: Eliminate timed delays in unit tests"

This commit is contained in:
Zuul 2022-08-17 15:14:54 +00:00 committed by Gerrit Code Review
commit 2efd0f1e29
2 changed files with 10 additions and 3 deletions

View File

@ -434,8 +434,13 @@ class ZeroIntervalWithTimeoutLoopingCall(
loopingcall.FixedIntervalWithTimeoutLoopingCall):
def start(self, interval, initial_delay=None,
stop_on_exception=True, timeout=0):
return super(ZeroIntervalWithTimeoutLoopingCall, self).start(
0, 0, stop_on_exception, timeout)
result = None
with mock.patch('time.time', side_effect=[0, (timeout + 1)]):
result = super(ZeroIntervalWithTimeoutLoopingCall, self).start(
0, 0, stop_on_exception, timeout)
return result
def replace_obj_loader(testcase, obj):

View File

@ -25,6 +25,7 @@ import requests
from cinder import context
from cinder import exception
from cinder.tests.unit import test
from cinder.tests.unit import utils as test_utils
from cinder.volume import configuration as conf
from cinder.volume.drivers.veritas_access import veritas_iscsi
@ -528,6 +529,8 @@ class ACCESSIscsiDriverTestCase(test.TestCase):
self._driver.initialize_connection(self.volume, self.connector)
self.assertEqual(1, self._driver._vrts_get_iscsi_properties.call_count)
@mock.patch('oslo_service.loopingcall.FixedIntervalWithTimeoutLoopingCall',
new=test_utils.ZeroIntervalWithTimeoutLoopingCall)
def test_initialize_connection_negative(self):
self.mock_object(self._driver, '_access_api')
self.mock_object(self._driver, '_get_vrts_lun_list')
@ -538,7 +541,6 @@ class ACCESSIscsiDriverTestCase(test.TestCase):
lun['lun_name'] = 'fakelun'
lun['target_name'] = 'iqn.2017-02.com.veritas:faketarget'
lun_list = {'output': {'output': {'luns': [lun]}}}
self._driver.LUN_FOUND_INTERVAL = 5
self._driver._get_vrts_lun_list.return_value = lun_list
self._driver._access_api.return_value = True