Skip to content

Commit 51960c4

Browse files
committed
test updates
1 parent 07d1e63 commit 51960c4

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

pymongo/network_layer.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ def __init__(self, timeout: Optional[float] = None):
256256
self._timeout = timeout
257257
self._closed = asyncio.get_running_loop().create_future()
258258
self._connection_lost = False
259-
self._closing_exception = None
260259

261260
def settimeout(self, timeout: float | None) -> None:
262261
self._timeout = timeout
@@ -270,11 +269,9 @@ def close(self, exc: Optional[Exception] = None) -> None:
270269
self.transport.abort()
271270
self._resolve_pending(exc)
272271
self._connection_lost = True
273-
self._closing_exception = exc # type:ignore[assignment]
274272

275273
def connection_lost(self, exc: Optional[Exception] = None) -> None:
276274
self._resolve_pending(exc)
277-
self._closing_exception = exc # type:ignore[assignment]
278275
if not self._closed.done():
279276
self._closed.set_result(None)
280277

@@ -338,11 +335,8 @@ async def read(self, request_id: Optional[int], max_message_size: int) -> tuple[
338335
if self._done_messages:
339336
message = await self._done_messages.popleft()
340337
else:
341-
if self._closed.done():
342-
if self._closing_exception:
343-
raise self._closing_exception
344-
else:
345-
raise OSError("connection closed")
338+
if self.transport and self.transport.is_closing():
339+
raise OSError("connection is already closed")
346340
read_waiter = asyncio.get_running_loop().create_future()
347341
self._pending_messages.append(read_waiter)
348342
try:
@@ -480,7 +474,6 @@ def _resolve_pending(self, exc: Optional[Exception] = None) -> None:
480474
else:
481475
msg.set_exception(exc)
482476
self._done_messages.append(msg)
483-
self._pending_messages.clear()
484477

485478

486479
class PyMongoKMSProtocol(PyMongoBaseProtocol):

test/connection_logging/connection-logging.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,22 +446,6 @@
446446
}
447447
}
448448
},
449-
{
450-
"level": "debug",
451-
"component": "connection",
452-
"data": {
453-
"message": "Connection pool cleared",
454-
"serverHost": {
455-
"$$type": "string"
456-
},
457-
"serverPort": {
458-
"$$type": [
459-
"int",
460-
"long"
461-
]
462-
}
463-
}
464-
},
465449
{
466450
"level": "debug",
467451
"component": "connection",
@@ -514,6 +498,22 @@
514498
]
515499
}
516500
}
501+
},
502+
{
503+
"level": "debug",
504+
"component": "connection",
505+
"data": {
506+
"message": "Connection pool cleared",
507+
"serverHost": {
508+
"$$type": "string"
509+
},
510+
"serverPort": {
511+
"$$type": [
512+
"int",
513+
"long"
514+
]
515+
}
516+
}
517517
}
518518
]
519519
}

test/connection_monitoring/pool-create-min-size-error.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
"isMaster",
1616
"hello"
1717
],
18-
"closeConnection": true,
18+
"blockConnection": true,
19+
"blockTimeMS": 1000,
1920
"appName": "poolCreateMinSizeErrorTest"
2021
}
2122
},
2223
"poolOptions": {
2324
"minPoolSize": 1,
2425
"backgroundThreadIntervalMS": 50,
26+
"socketTimeoutMS": 500,
27+
"connectTimeoutMS": 500,
2528
"appName": "poolCreateMinSizeErrorTest"
2629
},
2730
"operations": [
@@ -47,15 +50,15 @@
4750
"type": "ConnectionCreated",
4851
"address": 42
4952
},
50-
{
51-
"type": "ConnectionPoolCleared",
52-
"address": 42
53-
},
5453
{
5554
"type": "ConnectionClosed",
5655
"address": 42,
5756
"connectionId": 42,
5857
"reason": "error"
58+
},
59+
{
60+
"type": "ConnectionPoolCleared",
61+
"address": 42
5962
}
6063
],
6164
"ignore": [

test/load_balancer/sdam-error-handling.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@
274274
"client": "failPointClient",
275275
"failPoint": {
276276
"configureFailPoint": "failCommand",
277-
"mode": "alwaysOn",
277+
"mode": {
278+
"times": 1
279+
},
278280
"data": {
279281
"failCommands": [
280282
"isMaster",
@@ -294,9 +296,7 @@
294296
"x": 1
295297
}
296298
},
297-
"expectError": {
298-
"isClientError": true
299-
}
299+
"ignoreResultAndError": true
300300
}
301301
],
302302
"expectEvents": [
@@ -370,9 +370,6 @@
370370
{
371371
"connectionCreatedEvent": {}
372372
},
373-
{
374-
"poolClearedEvent": {}
375-
},
376373
{
377374
"connectionClosedEvent": {
378375
"reason": "error"
@@ -382,6 +379,9 @@
382379
"connectionCheckOutFailedEvent": {
383380
"reason": "connectionError"
384381
}
382+
},
383+
{
384+
"poolClearedEvent": {}
385385
}
386386
]
387387
}

0 commit comments

Comments
 (0)