Skip to content

Commit 2ddc2bb

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into spec-resync-12-22-2025
2 parents bb5ff23 + 18c1f14 commit 2ddc2bb

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

test/asynchronous/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,7 @@ def test_gevent_timeout_when_creating_connection(self):
23982398
client = self.async_rs_or_single_client()
23992399
self.addCleanup(client.close)
24002400
coll = client.pymongo_test.test
2401-
pool = async_get_pool(client)
2401+
pool = async_get_pool(client) # type:ignore
24022402

24032403
# Patch the pool to delay the connect method.
24042404
def delayed_connect(*args, **kwargs):

test/asynchronous/unified_format.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ async def _create_entity(self, entity_spec, uri=None):
329329
kwargs["h"] = uri
330330
client = await self.test.async_rs_or_single_client(**kwargs)
331331
await client.aconnect()
332+
# Wait for pool to be populated.
333+
if "awaitMinPoolSizeMS" in spec:
334+
pool = await async_get_pool(client)
335+
t0 = time.monotonic()
336+
while True:
337+
if (time.monotonic() - t0) > spec["awaitMinPoolSizeMS"] * 1000:
338+
raise ValueError("Test timed out during awaitMinPoolSize")
339+
async with pool.lock:
340+
if len(pool.conns) + pool.active_sockets >= pool.opts.min_pool_size:
341+
break
342+
await asyncio.sleep(0.1)
332343
self[spec["id"]] = client
333344
return
334345
elif entity_type == "database":
@@ -463,7 +474,7 @@ class UnifiedSpecTestMixinV1(AsyncIntegrationTest):
463474
a class attribute ``TEST_SPEC``.
464475
"""
465476

466-
SCHEMA_VERSION = Version.from_string("1.25")
477+
SCHEMA_VERSION = Version.from_string("1.26")
467478
RUN_ON_LOAD_BALANCER = True
468479
TEST_SPEC: Any
469480
TEST_PATH = "" # This gets filled in by generate_test_classes
@@ -1551,7 +1562,6 @@ async def test_case(self):
15511562
if re.search(fail_pattern, description):
15521563
test_method = unittest.expectedFailure(test_method)
15531564
break
1554-
15551565
setattr(cls, test_name, test_method)
15561566

15571567

test/asynchronous/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828

2929
from bson.son import SON
3030
from pymongo import AsyncMongoClient
31+
from pymongo.asynchronous.pool import Pool, _CancellationContext, _PoolGeneration
3132
from pymongo.errors import ConfigurationError
3233
from pymongo.hello import HelloCompat
3334
from pymongo.lock import _async_create_lock
3435
from pymongo.operations import _Op
3536
from pymongo.read_preferences import ReadPreference
3637
from pymongo.server_selectors import any_server_selector, writable_server_selector
37-
from pymongo.synchronous.pool import _CancellationContext, _PoolGeneration
3838

3939
_IS_SYNC = False
4040

4141

42-
async def async_get_pool(client):
42+
async def async_get_pool(client: AsyncMongoClient) -> Pool:
4343
"""Get the standalone, primary, or mongos pool."""
4444
topology = await client._get_topology()
4545
server = await topology._select_server(writable_server_selector, _Op.TEST)
4646
return server.pool
4747

4848

49-
async def async_get_pools(client):
49+
async def async_get_pools(client: AsyncMongoClient) -> list[Pool]:
5050
"""Get all pools."""
5151
return [
5252
server.pool

test/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ def test_gevent_timeout_when_creating_connection(self):
23532353
client = self.rs_or_single_client()
23542354
self.addCleanup(client.close)
23552355
coll = client.pymongo_test.test
2356-
pool = get_pool(client)
2356+
pool = get_pool(client) # type:ignore
23572357

23582358
# Patch the pool to delay the connect method.
23592359
def delayed_connect(*args, **kwargs):

test/unified_format.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ def _create_entity(self, entity_spec, uri=None):
328328
kwargs["h"] = uri
329329
client = self.test.rs_or_single_client(**kwargs)
330330
client._connect()
331+
# Wait for pool to be populated.
332+
if "awaitMinPoolSizeMS" in spec:
333+
pool = get_pool(client)
334+
t0 = time.monotonic()
335+
while True:
336+
if (time.monotonic() - t0) > spec["awaitMinPoolSizeMS"] * 1000:
337+
raise ValueError("Test timed out during awaitMinPoolSize")
338+
with pool.lock:
339+
if len(pool.conns) + pool.active_sockets >= pool.opts.min_pool_size:
340+
break
341+
time.sleep(0.1)
331342
self[spec["id"]] = client
332343
return
333344
elif entity_type == "database":
@@ -462,7 +473,7 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
462473
a class attribute ``TEST_SPEC``.
463474
"""
464475

465-
SCHEMA_VERSION = Version.from_string("1.25")
476+
SCHEMA_VERSION = Version.from_string("1.26")
466477
RUN_ON_LOAD_BALANCER = True
467478
TEST_SPEC: Any
468479
TEST_PATH = "" # This gets filled in by generate_test_classes
@@ -1536,7 +1547,6 @@ def test_case(self):
15361547
if re.search(fail_pattern, description):
15371548
test_method = unittest.expectedFailure(test_method)
15381549
break
1539-
15401550
setattr(cls, test_name, test_method)
15411551

15421552

test/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@
3434
from pymongo.operations import _Op
3535
from pymongo.read_preferences import ReadPreference
3636
from pymongo.server_selectors import any_server_selector, writable_server_selector
37-
from pymongo.synchronous.pool import _CancellationContext, _PoolGeneration
37+
from pymongo.synchronous.pool import Pool, _CancellationContext, _PoolGeneration
3838

3939
_IS_SYNC = True
4040

4141

42-
def get_pool(client):
42+
def get_pool(client: MongoClient) -> Pool:
4343
"""Get the standalone, primary, or mongos pool."""
4444
topology = client._get_topology()
4545
server = topology._select_server(writable_server_selector, _Op.TEST)
4646
return server.pool
4747

4848

49-
def get_pools(client):
49+
def get_pools(client: MongoClient) -> list[Pool]:
5050
"""Get all pools."""
5151
return [
5252
server.pool

0 commit comments

Comments
 (0)