Trivial: Fix flaky unit test

One cluster listener daemon isn't properly mocked, for which reason
it's running in a separate thread and calling mocked methods,
affecting other test cases and their assertions.

http://paste.openstack.org/raw/734339/

This change mocks it properly, ensuring that other test cases will
not be affected by it.

Change-Id: I2e9d2b98457bac280bf7a19afc12dc822a83eb0f
This commit is contained in:
Lucian Petrut 2018-11-07 10:14:20 +02:00
parent 728ddeb4f4
commit 21a2fe8758
1 changed files with 5 additions and 3 deletions

View File

@ -825,18 +825,18 @@ class ClusterUtilsTestCase(test_base.OsWinBaseTestCase):
mock_time.sleep.assert_called_once_with(
constants.DEFAULT_WMI_EVENT_TIMEOUT_MS / 1000)
@mock.patch.object(clusterutils._ClusterGroupOwnerChangeListener, 'get')
@mock.patch.object(clusterutils, '_ClusterGroupOwnerChangeListener')
@mock.patch.object(clusterutils.ClusterUtils, 'get_cluster_node_name')
@mock.patch.object(clusterutils.ClusterUtils, 'get_cluster_group_type')
@mock.patch.object(clusterutils, 'time')
def test_get_vm_owner_change_listener_v2(self, mock_time, mock_get_type,
mock_get_node_name,
mock_get_event):
mock_listener):
mock_get_type.side_effect = [
w_const.ClusGroupTypeVirtualMachine,
mock.sentinel.other_type]
mock_events = [mock.MagicMock(), mock.MagicMock()]
mock_get_event.side_effect = (
mock_listener.return_value.get.side_effect = (
mock_events + [exceptions.OSWinException, KeyboardInterrupt])
callback = mock.Mock()
@ -848,6 +848,8 @@ class ClusterUtilsTestCase(test_base.OsWinBaseTestCase):
callback.assert_called_once_with(
mock_events[0]['cluster_object_name'],
mock_get_node_name.return_value)
mock_listener.assert_called_once_with(
self._clusapi.open_cluster.return_value)
mock_get_node_name.assert_called_once_with(mock_events[0]['parent_id'])
mock_get_type.assert_any_call(mock_events[0]['cluster_object_name'])
mock_time.sleep.assert_called_once_with(