Skip to content

Commit 815c924

Browse files
authored
PYTHON-2136: added more diagnostic information for ServerSelectionTimeoutError (#444)
* PYTHON-2136: added more diagnostic information for ServerSelectionTimeoutError * made error message more human readable * fixed tests * fixed remaining testcase * fixed formatting * more formatting fixes
1 parent e608ff4 commit 815c924

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

pymongo/topology.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def _select_servers_loop(self, selector, timeout, address):
213213
# No suitable servers.
214214
if timeout == 0 or now > end_time:
215215
raise ServerSelectionTimeoutError(
216-
self._error_message(selector))
216+
"%s, Timeout: %ss, Topology Description: %r" %
217+
(self._error_message(selector), timeout, self.description))
217218

218219
self._ensure_opened()
219220
self._request_check_all()

test/test_replica_set_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ def test_connect_with_internal_ips(self):
343343
with self.assertRaises(AutoReconnect) as context:
344344
connected(client)
345345

346-
self.assertEqual(
347-
"Could not reach any servers in [('internal-ip', 27017)]."
346+
self.assertIn("Could not reach any servers in [('internal-ip', 27017)]."
348347
" Replica set is configured with internal hostnames or IPs?",
349348
str(context.exception))
350349

test/test_topology.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def assertMessage(self, message, topology, selector=any_server_selector):
766766
with self.assertRaises(ConnectionFailure) as context:
767767
topology.select_server(selector, server_selection_timeout=0)
768768

769-
self.assertEqual(message, str(context.exception))
769+
self.assertIn(message, str(context.exception))
770770

771771
def test_no_primary(self):
772772
t = create_mock_topology(replica_set_name='rs')

0 commit comments

Comments
 (0)