Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pymongo/replica_set_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def _send_message_with_response(self, msg, _connection_to_use=None,
except AutoReconnect, why:
self.disconnect()
errors.append(why)
raise AutoReconnect(', '.join(errors))
raise AutoReconnect(', '.join(map(str, errors)))

def __cmp__(self, other):
# XXX: Implement this?
Expand Down
9 changes: 9 additions & 0 deletions test/test_replica_set_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from bson.son import SON
from bson.tz_util import utc
from mock import Mock, patch
Copy link
Member

Choose a reason for hiding this comment

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

This is a new dependancy, can you confirm which mocking library this is?

from pymongo import ReadPreference
from pymongo.connection import Connection
from pymongo.replica_set_connection import ReplicaSetConnection
Expand Down Expand Up @@ -157,6 +158,14 @@ def make_db(base, name):
self.assertEqual(connection.test, Database(connection, "test"))
connection.close()

def test_auto_reconnect_exception_when_read_preference_is_secondary(self):
c = self._get_connection()
db = c.pymongo_test

with patch('socket.socket.sendall', Mock(side_effect=socket.error)):
cursor = db.test.find(read_preference=ReadPreference.SECONDARY)
self.assertRaises(AutoReconnect, cursor.next)

def test_operations(self):
c = self._get_connection()

Expand Down