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

Avoid race condition in event_reactor test #572

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

cottsay
Copy link
Member

@cottsay cottsay commented Aug 10, 2023

These tests essentially queue an event, wait for the event reactor to process the event, and check that an appropriate function was or was not called. The way we were previously waiting for the event reactor thread to do the work left a window between popping the work from the queue and actually passing the event to the observers. If the flush loop finished early in this window, there was a chance that the test's assert would beat the event reactor, which hadn't yet invoked the observers.

Rather than change the behavior of the flush function to also ensure that the popped work had completed processing, we can simply use the queue's integrated work tracking, which won't unblock until there is no work in the queue OR processing.

I believe that this is the cause of the sporadic CI failures in this repository.

These tests essentially queue an event, wait for the event reactor to
process the event, and check that an appropriate function was or was not
called. The way we were previously waiting for the event reactor thread
to do the work left a window between popping the work from the queue and
actually passing the event to the observers. If the flush loop finished
early in this window, there was a chance that the test's assert would
beat the event reactor, which hadn't yet invoked the observers.

Rather than change the behavior of the flush function to also ensure
that the popped work had completed processing, we can simply use the
queue's integrated work tracking, which won't unblock until there is no
work in the queue OR processing.
@cottsay cottsay added the bug Something isn't working label Aug 10, 2023
@cottsay cottsay self-assigned this Aug 10, 2023
@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.11% ⚠️

Comparison is base (7b70e61) 81.88% compared to head (acebcaf) 81.77%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #572      +/-   ##
==========================================
- Coverage   81.88%   81.77%   -0.11%     
==========================================
  Files          62       62              
  Lines        3648     3648              
  Branches      705      705              
==========================================
- Hits         2987     2983       -4     
- Misses        609      612       +3     
- Partials       52       53       +1     

see 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@nuclearsandwich nuclearsandwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Significantly cleaner 🙇🏼

@cottsay cottsay merged commit 3467373 into master Aug 17, 2023
35 checks passed
@cottsay cottsay deleted the cottsay/event-reactor-race branch August 17, 2023 22:18
@cottsay cottsay added this to the 0.13.0 milestone Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

2 participants