Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relax timing race in event_reactor test #345

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions test/test_event_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,31 @@ def test_create_event_reactor():
assert isinstance(queue, Queue)

# use larger interval to prevent different timing to effect the results
event_reactor.TIMER_INTERVAL = 0.25
event_reactor.TIMER_INTERVAL = 1.0

# add a few dummy events
with patch('colcon_core.event_reactor.logger.error') as error:
assert error.call_count == 0

queue.put(('first', None))
event_reactor.flush()
assert error.call_count == 1

queue.put(('second', None))
queue.put(('third', None))
event_reactor.flush()
assert error.call_count == 1

# check the collected events so far
queue.put(('third', None))
event_reactor.flush()
assert error.call_count == 2

# 1 timer event, 3 mock string events
assert len(event_reactor._observers[0].events) == 4
assert len(event_reactor._observers[1].events) == 4
# both observers got the timer event
assert isinstance(event_reactor._observers[0].events[0][0], TimerEvent)
assert isinstance(event_reactor._observers[1].events[0][0], TimerEvent)
# both observers got the 3 mock string events
assert event_reactor._observers[0].events[1:] == \
[('first', None), ('second', None), ('third', None)]
assert event_reactor._observers[1].events[1:] == \
Expand All @@ -88,7 +99,7 @@ def test_create_event_reactor():
'custom exception\n')

# wait for another timer event to be generated
time.sleep(event_reactor.TIMER_INTERVAL)
time.sleep(1.5 * event_reactor.TIMER_INTERVAL)
assert len(event_reactor._observers[0].events) == 5
assert len(event_reactor._observers[1].events) == 5
assert isinstance(
Expand Down