Tests: replace mocking loopingcall with zero interval

We mock sleep(), but LoopingCall, depending on version either uses
a private wrapper around eventlet.Event or one from oslo_utils.
Since mocking them correctly requires mocking private methods, this
change sets the loop interval to zero, bypassing waiting.

This reduces the time required for running disk_partitioner tests
from 20 seconds to less than 1 second.

Change-Id: I49340bfedd3e63316a79f166ce0874d5020b862a
This commit is contained in:
Dmitry Tantsur 2019-04-25 16:06:25 +02:00
parent 899d255b4a
commit 93d3a75039
1 changed files with 6 additions and 5 deletions

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import eventlet
import mock
from testtools.matchers import HasLength
@ -23,6 +22,9 @@ from ironic_lib.tests import base
from ironic_lib import utils
CONF = disk_partitioner.CONF
class DiskPartitionerTestCase(base.IronicLibTestCase):
def test_add_partition(self):
@ -99,12 +101,12 @@ class DiskPartitionerTestCase(base.IronicLibTestCase):
'fuser', '/dev/fake', run_as_root=True,
check_exit_code=[0, 1])
@mock.patch.object(eventlet.greenthread, 'sleep', lambda seconds: None)
@mock.patch.object(disk_partitioner.DiskPartitioner, '_exec',
autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_commit_with_device_is_busy_once(self, mock_utils_exc,
mock_disk_partitioner_exec):
CONF.set_override('check_device_interval', 0, group='disk_partitioner')
dp = disk_partitioner.DiskPartitioner('/dev/fake')
fake_parts = [(1, {'boot_flag': None,
'extra_flags': None,
@ -134,12 +136,12 @@ class DiskPartitionerTestCase(base.IronicLibTestCase):
check_exit_code=[0, 1])
self.assertEqual(2, mock_utils_exc.call_count)
@mock.patch.object(eventlet.greenthread, 'sleep', lambda seconds: None)
@mock.patch.object(disk_partitioner.DiskPartitioner, '_exec',
autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_commit_with_device_is_always_busy(self, mock_utils_exc,
mock_disk_partitioner_exec):
CONF.set_override('check_device_interval', 0, group='disk_partitioner')
dp = disk_partitioner.DiskPartitioner('/dev/fake')
fake_parts = [(1, {'boot_flag': None,
'extra_flags': None,
@ -169,13 +171,12 @@ class DiskPartitionerTestCase(base.IronicLibTestCase):
check_exit_code=[0, 1])
self.assertEqual(20, mock_utils_exc.call_count)
# Mock the eventlet.greenthread.sleep for the looping_call
@mock.patch.object(eventlet.greenthread, 'sleep', lambda seconds: None)
@mock.patch.object(disk_partitioner.DiskPartitioner, '_exec',
autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_commit_with_device_disconnected(self, mock_utils_exc,
mock_disk_partitioner_exec):
CONF.set_override('check_device_interval', 0, group='disk_partitioner')
dp = disk_partitioner.DiskPartitioner('/dev/fake')
fake_parts = [(1, {'boot_flag': None,
'extra_flags': None,