Skip to content

Commit cfeb7c4

Browse files
committed
No SSL no auth single tests passing
1 parent bbe4ef8 commit cfeb7c4

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

pymongo/network_layer.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def close(self):
101101
await self.conn[1].wait_closed()
102102

103103
def is_closing(self):
104-
self.conn[0].is_closing()
104+
return self.conn[0].is_closing()
105105

106106
@property
107107
def get_conn(self) -> PyMongoProtocol:
@@ -340,10 +340,11 @@ def connection_lost(self, exc):
340340
self._connection_lost = True
341341
pending = list(self._pending_messages)
342342
for msg in pending:
343-
if exc is None:
344-
msg.set_result(None)
345-
else:
346-
msg.set_exception(exc)
343+
if not msg.done():
344+
if exc is None:
345+
msg.set_result(None)
346+
else:
347+
msg.set_exception(exc)
347348
self._done_messages.append(msg)
348349

349350
if not self._closed.done():
@@ -374,7 +375,7 @@ def data(self):
374375
return self._buffer
375376

376377
async def wait_closed(self):
377-
await self._closed
378+
await asyncio.wait([self._closed])
378379

379380

380381
async def async_sendall(conn: PyMongoProtocol, buf: bytes) -> None:
@@ -500,10 +501,10 @@ async def async_receive_message(
500501
) -> Union[_OpReply, _OpMsg]:
501502
"""Receive a raw BSON message or raise socket.error."""
502503
timeout: Optional[Union[float, int]]
504+
timeout = conn.conn.gettimeout
503505
if _csot.get_timeout():
504506
deadline = _csot.get_deadline()
505507
else:
506-
timeout = conn.conn.get_conn.gettimeout
507508
if timeout:
508509
deadline = time.monotonic() + timeout
509510
else:
@@ -517,24 +518,31 @@ async def async_receive_message(
517518
cancellation_task = create_task(_poll_cancellation(conn))
518519
read_task = create_task(conn.conn.get_conn.read(request_id, max_message_size, debug))
519520
tasks = [read_task, cancellation_task]
520-
done, pending = await asyncio.wait(tasks, timeout=timeout, return_when=asyncio.FIRST_COMPLETED)
521-
for task in pending:
522-
task.cancel()
523-
if pending:
524-
await asyncio.wait(pending)
525-
if len(done) == 0:
526-
raise socket.timeout("timed out")
527-
if read_task in done:
528-
data, op_code = read_task.result()
529-
530-
try:
531-
unpack_reply = _UNPACK_REPLY[op_code]
532-
except KeyError:
533-
raise ProtocolError(
534-
f"Got opcode {op_code!r} but expected {_UNPACK_REPLY.keys()!r}"
535-
) from None
536-
return unpack_reply(data)
537-
raise _OperationCancelled("operation cancelled")
521+
try:
522+
done, pending = await asyncio.wait(
523+
tasks, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
524+
)
525+
for task in pending:
526+
task.cancel()
527+
if pending:
528+
await asyncio.wait(pending)
529+
if len(done) == 0:
530+
raise socket.timeout("timed out")
531+
if read_task in done:
532+
data, op_code = read_task.result()
533+
try:
534+
unpack_reply = _UNPACK_REPLY[op_code]
535+
except KeyError:
536+
raise ProtocolError(
537+
f"Got opcode {op_code!r} but expected {_UNPACK_REPLY.keys()!r}"
538+
) from None
539+
return unpack_reply(data)
540+
raise _OperationCancelled("operation cancelled")
541+
except asyncio.CancelledError:
542+
for task in tasks:
543+
task.cancel()
544+
await asyncio.wait(tasks)
545+
raise
538546

539547

540548
def receive_message(

test/asynchronous/test_connection_monitoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ async def cleanup():
280280
for t in self.targets.values():
281281
await t.join(5)
282282
for conn in self.labels.values():
283-
conn.close_conn(None)
283+
await conn.close_conn(None)
284284

285285
self.addAsyncCleanup(cleanup)
286286

test/asynchronous/test_pooling.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async def run_mongo_thread(self):
124124
self.state = "connection"
125125

126126
def __del__(self):
127-
if self.sock:
127+
if _IS_SYNC and self.sock:
128128
self.sock.close_conn(None)
129129

130130

@@ -215,7 +215,7 @@ async def test_pool_removes_closed_socket(self):
215215

216216
async with cx_pool.checkout() as conn:
217217
# Use Connection's API to close the socket.
218-
conn.close_conn(None)
218+
await conn.close_conn(None)
219219

220220
self.assertEqual(0, len(cx_pool.conns))
221221

@@ -228,7 +228,7 @@ async def test_pool_removes_dead_socket(self):
228228
async with cx_pool.checkout() as conn:
229229
# Simulate a closed socket without telling the Connection it's
230230
# closed.
231-
conn.conn.close()
231+
await conn.conn.close()
232232
self.assertTrue(conn.conn_closed())
233233

234234
async with cx_pool.checkout() as new_connection:
@@ -302,7 +302,7 @@ async def test_pool_check(self):
302302
async with cx_pool.checkout() as conn:
303303
# Simulate a closed socket without telling the Connection it's
304304
# closed.
305-
conn.conn.close()
305+
await conn.conn.close()
306306

307307
# Swap pool's address with a bad one.
308308
address, cx_pool.address = cx_pool.address, ("foo.com", 1234)
@@ -373,7 +373,7 @@ async def test_checkout_more_than_max_pool_size(self):
373373
self.assertEqual(t.state, "get_socket")
374374

375375
for socket_info in socks:
376-
socket_info.close_conn(None)
376+
await socket_info.close_conn(None)
377377

378378
async def test_maxConnecting(self):
379379
client = await self.async_rs_or_single_client()

test/test_pooling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def run_mongo_thread(self):
124124
self.state = "connection"
125125

126126
def __del__(self):
127-
if self.sock:
127+
if _IS_SYNC and self.sock:
128128
self.sock.close_conn(None)
129129

130130

0 commit comments

Comments
 (0)