Skip to content

Commit 70b4113

Browse files
committed
fix and update tests
1 parent da0c0e5 commit 70b4113

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ uv sync ${UV_ARGS} --reinstall --quiet
3030
uv pip list
3131

3232
# Start the test runner.
33-
uv run ${UV_ARGS} .evergreen/scripts/run_tests.py -vv test/asynchronous/test_pooling.py
33+
uv run ${UV_ARGS} .evergreen/scripts/run_tests.py "$@"
3434

3535
popd

pymongo/asynchronous/pool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@
5353
DocumentTooLarge,
5454
ExecutionTimeout,
5555
InvalidOperation,
56+
NetworkTimeout,
5657
NotPrimaryError,
5758
OperationFailure,
5859
PyMongoError,
5960
WaitQueueTimeoutError,
61+
_OperationCancelled,
6062
)
6163
from pymongo.hello import Hello, HelloCompat
6264
from pymongo.helpers_shared import _get_timeout_details, format_timeout_details
@@ -1107,7 +1109,9 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11071109
async with self.lock:
11081110
self.active_contexts.discard(conn.cancel_context)
11091111
# Enter backoff mode and reconnect on establishment failure.
1110-
if isinstance(e, ConnectionFailure):
1112+
if isinstance(e, ConnectionFailure) and not isinstance(
1113+
e, (_OperationCancelled, NetworkTimeout)
1114+
):
11111115
self._backoff += 1
11121116
# TODO: emit a message about backoff.
11131117
return await self.connect(handler)

pymongo/synchronous/pool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
DocumentTooLarge,
5151
ExecutionTimeout,
5252
InvalidOperation,
53+
NetworkTimeout,
5354
NotPrimaryError,
5455
OperationFailure,
5556
PyMongoError,
5657
WaitQueueTimeoutError,
58+
_OperationCancelled,
5759
)
5860
from pymongo.hello import Hello, HelloCompat
5961
from pymongo.helpers_shared import _get_timeout_details, format_timeout_details
@@ -1103,7 +1105,9 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
11031105
with self.lock:
11041106
self.active_contexts.discard(conn.cancel_context)
11051107
# Enter backoff mode and reconnect on establishment failure.
1106-
if isinstance(e, ConnectionFailure):
1108+
if isinstance(e, ConnectionFailure) and not isinstance(
1109+
e, (_OperationCancelled, NetworkTimeout)
1110+
):
11071111
self._backoff += 1
11081112
# TODO: emit a message about backoff.
11091113
return self.connect(handler)

test/asynchronous/test_pooling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ async def test_connection_timeout_message(self):
508508
with self.assertRaises(Exception) as error:
509509
await client.admin.command("ping")
510510

511-
if "(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)" not in str(
512-
error.exception
513-
):
514-
raise error.exception
511+
self.assertIn(
512+
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)",
513+
str(error.exception),
514+
)
515515

516516
@async_client_context.require_failCommand_appName
517517
async def test_pool_backoff_preserves_existing_collections(self):

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@
99
],
1010
"failPoint": {
1111
"configureFailPoint": "failCommand",
12-
"mode": {
13-
"times": 50
14-
},
12+
"mode": "alwaysOn",
1513
"data": {
1614
"failCommands": [
1715
"isMaster",
1816
"hello"
1917
],
20-
"closeConnection": true,
18+
"closeConnection": false,
19+
"blockConnection": true,
20+
"blockTimeMS": 1000,
2121
"appName": "poolCreateMinSizeErrorTest"
2222
}
2323
},
2424
"poolOptions": {
2525
"minPoolSize": 1,
2626
"backgroundThreadIntervalMS": 50,
27+
"socketTimeoutMS": 500,
28+
"connectTimeoutMS": 500,
2729
"appName": "poolCreateMinSizeErrorTest"
2830
},
2931
"operations": [

test/test_pooling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ def test_connection_timeout_message(self):
506506
with self.assertRaises(Exception) as error:
507507
client.admin.command("ping")
508508

509-
if "(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)" not in str(
510-
error.exception
511-
):
512-
raise error.exception
509+
self.assertIn(
510+
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)",
511+
str(error.exception),
512+
)
513513

514514
@client_context.require_failCommand_appName
515515
def test_pool_backoff_preserves_existing_collections(self):

0 commit comments

Comments
 (0)