-
Notifications
You must be signed in to change notification settings - Fork 177
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
Fix flaky subscription smoketests #1536
Conversation
@@ -64,7 +64,7 @@ def test_add_then_remove_index(self): | |||
# There are no indices, resulting in an unsupported unindexed join. | |||
self.publish_module(name, clear = False) | |||
with self.assertRaises(Exception): | |||
self.subscribe(self.JOIN_QUERY, n = 0) | |||
self.subscribe(self.JOIN_QUERY, n = 0)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding this ()
causes us to wait for the subscription results (which, in this case, will throw an exception).
This is the same for the lines below.
@bfops what's the race condition and why does this change make it so that we're no longer relying on it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, makes sense 👍
I updated the PR description with the details from the issue as well. Does the current explanation make sense? tl;dr we were creating a subscription but not waiting for it to complete within the |
Dismissing because Josh has outstanding questions and I don't want to accidentally merge without addressing those
if proc.poll() is not None: | ||
if proc.returncode: | ||
raise subprocess.CalledProcessError(proc.returncode, fake_args) | ||
return lambda timeout=None: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the source of the race condition - if the CLI process failed quickly enough, we would raise this exception synchronously in the call to subscribe
. But if the process took a bit longer to fail, then the block below would be the one to raise the exception, which would only be raised to the caller when the caller actually joined the background thread and waited for the subscription to complete.
By removing this block, we now only get exceptions when we wait for the subscription result. We will never get the exception synchronously. This eliminates the race condition - we must always wait for the subscription to complete in order to see the exception.
I have updated the tests accordingly.
smoketests/__init__.py
Outdated
# Note that we're returning `.join`, not `.join()`; this returns something that the caller can call in order to | ||
# join the thread and wait for the results. | ||
# If the caller does not invoke this returned value, the thread will just run in the background and not be awaited. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
# This is a custom thread class that will propagate an exception to the caller of `.join()`. | ||
# This is required because, by default, threads do not propagate exceptions to their callers, | ||
# even callers who have called `join`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
…ert the always-wait behavior of smoketest from #1536
Description of Changes
Fixes #1527. From there:
Those blocks of code would create a subscription (in a background thread), but not necessarily wait for it to complete. I believe there was a small race condition where we could exit the
assertRaises
block before getting the exception (see the logs in the linked ticket).I have updated these calls to wait for the subscription to finish, which re-raises any exceptions that occur in the background thread. Note this is due to
subscribe
using a custom thread class - this re-raising does not happen by default in Python.API and ABI breaking changes
No
Expected complexity level and risk
1
Testing
The CI currently passes, so it's not obviously-broken.
I was not able to reproduce the failure locally (at least, for the amount of time I was willing to wait). So, my only testing is that the tests still pass. It's probably not more flaky.
If anybody else wants to try, this was the loop I used: