Skip to content

Commit 9e123e3

Browse files
committed
PYTHON-1235 - Fix auto reconnect test under Jython 2.7
1 parent 80fdf61 commit 9e123e3

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

test/test_replica_set_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,19 @@ def test_auto_reconnect_exception_when_read_preference_is_secondary(self):
382382
def raise_socket_error(*args, **kwargs):
383383
raise socket.error
384384

385-
old_sendall = socket.socket.sendall
386-
socket.socket.sendall = raise_socket_error
385+
# In Jython 2.7 socket.socket is a function, not a class.
386+
sock = socket.socket()
387+
klass = sock.__class__
388+
old_sendall = klass.sendall
389+
klass.sendall = raise_socket_error
387390

388391
try:
389392
cursor = db.test.find(read_preference=ReadPreference.SECONDARY)
390393
self.assertRaises(AutoReconnect, cursor.next)
391394
finally:
392-
socket.socket.sendall = old_sendall
395+
klass.sendall = old_sendall
396+
# Silence resource warnings.
397+
sock.close()
393398

394399
def test_operations(self):
395400
c = self._get_client()

0 commit comments

Comments
 (0)