PYTHON-1897 Don't open new threads/sockets when closing a client

This commit is contained in:
Shane Harvey 2019-07-17 13:52:12 -07:00
parent 6d5d36186a
commit 010e8d429b
2 changed files with 10 additions and 1 deletions

View File

@ -431,7 +431,9 @@ class Topology(object):
# Mark all servers Unknown.
self._description = self._description.reset()
self._update_servers()
for address, sd in self._description.server_descriptions().items():
if address in self._servers:
self._servers[address].description = sd
# Stop SRV polling thread.
if self._srv_monitor:

View File

@ -743,6 +743,13 @@ class TestClient(IntegrationTest):
client.close()
self.assertTrue(client._kill_cursors_executor._stopped)
def test_close_does_not_open_servers(self):
client = rs_client(connect=False)
topology = client._topology
self.assertEqual(topology._servers, {})
client.close()
self.assertEqual(topology._servers, {})
def test_bad_uri(self):
with self.assertRaises(InvalidURI):
MongoClient("http://localhost")