-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2938 Fix race condition caused by MongoClient._process_periodic_tasks(client) #752
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5bdb69b
catch InvalidOperation
juliusgeo 8dfd430
add testing, raise InvalidOperation so it can be caught in _process_p…
juliusgeo 877d90a
remove error code that doesn't need to be there
juliusgeo 995269a
use rs_or_single_client
juliusgeo acd5cf3
add more test, shane fixes
juliusgeo 20c43b0
fix typo
juliusgeo 4a090c7
shane fixes
juliusgeo 13560f8
add comment
juliusgeo 8031988
change test so it works
juliusgeo 9119aaf
Merge branch 'master' into PYTHON-2938
juliusgeo 8a59524
shane fixes
juliusgeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1591,6 +1591,24 @@ def test_network_error_message(self): | |
with self.assertRaisesRegex(AutoReconnect, expected): | ||
client.pymongo_test.test.find_one({}) | ||
|
||
@unittest.skipIf('PyPy' in sys.version, 'PYTHON-2938 could fail on PyPy') | ||
def test_process_periodic_tasks(self): | ||
client = rs_or_single_client() | ||
coll = client.db.collection | ||
coll.insert_many([{} for _ in range(5)]) | ||
cursor = coll.find(batch_size=2) | ||
cursor.next() | ||
c_id = cursor.cursor_id | ||
self.assertIsNotNone(c_id) | ||
client.close() | ||
# Add cursor to kill cursors queue | ||
del cursor | ||
wait_until(lambda: client._MongoClient__kill_cursors_queue, | ||
"waited for cursor to be added to queue") | ||
client._process_periodic_tasks() # This must not raise or print any exceptions | ||
with self.assertRaises(InvalidOperation): | ||
coll.insert_many([{} for _ in range(5)]) | ||
|
||
@unittest.skipUnless( | ||
_HAVE_DNSPYTHON, "DNS-related tests need dnspython to be installed") | ||
def test_service_name_from_kwargs(self): | ||
|
@@ -1613,6 +1631,7 @@ def test_service_name_from_kwargs(self): | |
'customname') | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need the try/except/fail here. Just call client._process_periodic_tasks(). If that raises unexpectedly the teat will fail automatically. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
class TestExhaustCursor(IntegrationTest): | ||
"""Test that clients properly handle errors from exhaust cursors.""" | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I suspect this test will fail on PyPy because garbage collection works slightly differently. Let's skip this test entirely when running with PyPy (see my current PR for how to do that)
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.
Done.