| 1559 | |
| 1560 | @client_context.require_no_mongos |
| 1561 | def test_exhaust_network_error(self): |
| 1562 | # When doing an exhaust query, the socket stays checked out on success |
| 1563 | # but must be checked in on error to avoid semaphore leaks. |
| 1564 | client = self.rs_or_single_client(maxPoolSize=1, retryReads=False) |
| 1565 | collection = client.pymongo_test.test |
| 1566 | pool = get_pool(client) |
| 1567 | pool._check_interval_seconds = None # Never check. |
| 1568 | |
| 1569 | # Ensure a socket. |
| 1570 | connected(client) |
| 1571 | |
| 1572 | # Cause a network error. |
| 1573 | conn = one(pool.conns) |
| 1574 | conn.conn.close() |
| 1575 | cursor = collection.find(cursor_type=CursorType.EXHAUST) |
| 1576 | with self.assertRaises(ConnectionFailure): |
| 1577 | next(cursor) |
| 1578 | |
| 1579 | self.assertTrue(conn.closed) |
| 1580 | |
| 1581 | # The semaphore was decremented despite the error. |
| 1582 | self.assertEqual(0, pool.requests) |
| 1583 | |
| 1584 | @client_context.require_auth |
| 1585 | def test_auth_network_error(self): |