-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Remove MongoDBProxy and Migrate to Native PyMongo Retry Functionality #35213
Closed
Closed
Changes from all commits
Commits
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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -16,11 +16,17 @@ class TestHeartbeatFailureException(unittest.TestCase): | |
|
||
@patch('pymongo.MongoClient') | ||
@patch('pymongo.database.Database') | ||
def test_heartbeat_raises_exception_when_connection_alive_is_false(self, *calls): | ||
# pylint: disable=W0613 | ||
with patch('mongodb_proxy.MongoProxy') as mock_proxy: | ||
mock_proxy.return_value.admin.command.side_effect = ConnectionFailure('Test') | ||
useless_conn = MongoPersistenceBackend('useless', 'useless', 'useless') | ||
|
||
with pytest.raises(HeartbeatFailure): | ||
useless_conn.heartbeat() | ||
def test_heartbeat_retries_on_failure(self, MockDatabase, MockClient): | ||
# Setup mock client and database | ||
mock_client = MockClient.return_value | ||
mock_database = MockDatabase.return_value | ||
mock_database.admin.command.side_effect = ConnectionFailure('Test') | ||
|
||
useless_conn = MongoPersistenceBackend('useless', 'useless', 'useless') | ||
|
||
# Verify that the heartbeat method raises a HeartbeatFailure | ||
with pytest.raises(HeartbeatFailure): | ||
useless_conn.heartbeat() | ||
|
||
# Assert that retries are handled correctly | ||
self.assertGreater(mock_database.admin.command.call_count, 1) # Ensure retries happened | ||
Comment on lines
+31
to
+32
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. Nice, thanks for testing this. |
This file contains 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 |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
import logging | ||
|
||
import pymongo | ||
from mongodb_proxy import MongoProxy | ||
from pymongo.read_preferences import ( # lint-amnesty, pylint: disable=unused-import | ||
ReadPreference, | ||
_MONGOS_MODES, | ||
|
@@ -66,14 +65,6 @@ def connect_to_mongodb( | |
connection_params.update({'username': user, 'password': password, 'authSource': db}) | ||
|
||
mongo_conn = pymongo.MongoClient(**connection_params) | ||
|
||
if proxy: | ||
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. Since |
||
mongo_conn = MongoProxy( | ||
mongo_conn[db], | ||
wait_time=retry_wait_time | ||
) | ||
return mongo_conn | ||
|
||
return mongo_conn[db] | ||
|
||
|
||
|
Oops, something went wrong.
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.
to satisfy pycodestyle, you'll need to remove these now-empty lines