Mock time.sleep() in 3 unit tests
No need to actually wait in unit tests. This patch decreases the unit tests run time by about 24 seconds. Change-Id: I502e15e0fd2d8238f6b6b7089eb38d4d7b55114b
This commit is contained in:
parent
f9b4e55db5
commit
123caab41d
@ -2474,12 +2474,14 @@ class ScaleIOConnectorTestCase(ConnectorTestCase):
|
||||
|
||||
self.assertRaises(exception.BrickException, self.test_connect_volume)
|
||||
|
||||
def test_error_path_not_found(self):
|
||||
@mock.patch('time.sleep')
|
||||
def test_error_path_not_found(self, sleep_mock):
|
||||
"""Timeout waiting for volume to map to local file system"""
|
||||
mock.patch.object(
|
||||
os, 'listdir', return_value=["emc-vol-no-volume"]
|
||||
).start()
|
||||
self.assertRaises(exception.BrickException, self.test_connect_volume)
|
||||
self.assertTrue(sleep_mock.called)
|
||||
|
||||
def test_map_volume_already_mapped(self):
|
||||
"""Ignore REST API failure for volume already mapped"""
|
||||
|
@ -73,7 +73,8 @@ class LinuxSCSITestCase(base.TestCase):
|
||||
('tee -a /sys/block/sdc/device/delete')]
|
||||
self.assertEqual(expected_commands, self.cmds)
|
||||
|
||||
def test_wait_for_volume_removal(self):
|
||||
@mock.patch('time.sleep')
|
||||
def test_wait_for_volume_removal(self, sleep_mock):
|
||||
fake_path = '/dev/disk/by-path/fake-iscsi-iqn-lun-0'
|
||||
exists_mock = mock.Mock()
|
||||
exists_mock.return_value = True
|
||||
@ -88,6 +89,7 @@ class LinuxSCSITestCase(base.TestCase):
|
||||
self.linuxscsi.wait_for_volume_removal(fake_path)
|
||||
expected_commands = []
|
||||
self.assertEqual(expected_commands, self.cmds)
|
||||
self.assertTrue(sleep_mock.called)
|
||||
|
||||
def test_flush_multipath_device(self):
|
||||
self.linuxscsi.flush_multipath_device('/dev/dm-9')
|
||||
@ -117,8 +119,9 @@ class LinuxSCSITestCase(base.TestCase):
|
||||
expected_path = '/dev/disk/by-id/dm-uuid-mpath-%s' % fake_wwn
|
||||
self.assertEqual(expected_path, found_path)
|
||||
|
||||
@mock.patch('time.sleep')
|
||||
@mock.patch.object(os.path, 'exists')
|
||||
def test_find_multipath_device_path_mapper(self, exists_mock):
|
||||
def test_find_multipath_device_path_mapper(self, exists_mock, sleep_mock):
|
||||
# the wait loop tries 3 times before it gives up
|
||||
# we want to test failing to find the
|
||||
# /dev/disk/by-id/dm-uuid-mpath-<WWN> path
|
||||
@ -129,6 +132,7 @@ class LinuxSCSITestCase(base.TestCase):
|
||||
found_path = self.linuxscsi.find_multipath_device_path(fake_wwn)
|
||||
expected_path = '/dev/mapper/%s' % fake_wwn
|
||||
self.assertEqual(expected_path, found_path)
|
||||
self.assertTrue(sleep_mock.called)
|
||||
|
||||
@mock.patch.object(os.path, 'exists', return_value=False)
|
||||
@mock.patch.object(time, 'sleep')
|
||||
|
Loading…
x
Reference in New Issue
Block a user