Skip to content

Commit

Permalink
[#479] Remove check for initial event
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillmakhonin committed Oct 25, 2018
1 parent 4223e86 commit cf23439
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/python/test_k8s_properties_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit cf23439

Please sign in to comment.