diff --git a/tests/python/test_k8s_properties_storages.py b/tests/python/test_k8s_properties_storages.py index 82e69a291..682b8772e 100644 --- a/tests/python/test_k8s_properties_storages.py +++ b/tests/python/test_k8s_properties_storages.py @@ -44,6 +44,18 @@ LOGGER = logging.getLogger(__name__) +def last_event_is_modification(events): + """ + Check that last event has modification type + + :param events: list of events with types + :type events: list[tuple[str, Any]] + :return: bool -- resultat of checking + """ + + return len(events) > 1 and events[-1][0] == legion.k8s.EVENT_MODIFIED + + class TestK8SPropertiesStorage(unittest2.TestCase): @classmethod def setUpClass(cls): @@ -132,17 +144,13 @@ def listener(): events.append((event, new_data)) with legion_test.utils.ContextThread(listener): - LOGGER.info('Waiting for creation event') - self.assertTrue(legion_test.utils.wait_until(lambda: len(events) > 0, 1, 5), - 'Creation event has not been recieved for {!r}'.format(storage_name)) - LOGGER.info('Updating inside listener loop') storage_to_write[key] = second_value storage_to_write.save() LOGGER.info('Checking update') - self.assertTrue(legion_test.utils.wait_until(lambda: len(events) > 1, 1, 5), + self.assertTrue(legion_test.utils.wait_until(lambda: last_event_is_modification(events), 1, 5), 'Modification event has not been recieved for {!r}'.format(storage_name)) self.assertTupleEqual(events[-1], (legion.k8s.EVENT_MODIFIED, {key: second_value}), 'Wrong modification event object') @@ -175,17 +183,13 @@ def listener(): events.append((event, new_data)) with legion_test.utils.ContextThread(listener): - LOGGER.info('Waiting for creation event') - self.assertTrue(legion_test.utils.wait_until(lambda: len(events) > 0, 1, 5), - 'Creation event has not been recieved for {!r}'.format(storage_name)) - LOGGER.info('Updating inside listener loop') storage_to_write[key] = second_value storage_to_write.save() LOGGER.info('Checking update') - self.assertTrue(legion_test.utils.wait_until(lambda: len(events) > 1, 1, 5), + self.assertTrue(legion_test.utils.wait_until(lambda: last_event_is_modification(events), 1, 5), 'Modification event has not been recieved for {!r}'.format(storage_name)) self.assertTupleEqual(events[-1], (legion.k8s.EVENT_MODIFIED, {key: second_value}), 'Wrong modification event object')