Skip to content

Commit 6623261

Browse files
committed
fix maxconnecting test
1 parent 771570d commit 6623261

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

test/asynchronous/test_pooling.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from pymongo.errors import AutoReconnect, ConnectionFailure, DuplicateKeyError
3030
from pymongo.hello import HelloCompat
3131
from pymongo.lock import _async_create_lock
32+
from pymongo.read_preferences import ReadPreference
3233

3334
sys.path[0:0] = [""]
3435

@@ -397,7 +398,8 @@ async def test_checkout_more_than_max_pool_size(self):
397398
async def _check_maxConnecting(
398399
self, client: AsyncMongoClient, backoff=False
399400
) -> tuple[int, int]:
400-
await client.test.test.insert_one({})
401+
coll = client.test.test.with_options(read_preference=ReadPreference.PRIMARY)
402+
await coll.insert_one({})
401403

402404
pool = await async_get_pool(client)
403405
if backoff:
@@ -406,15 +408,15 @@ async def _check_maxConnecting(
406408

407409
# Run 50 short running operations
408410
async def find_one():
409-
docs.append(await client.test.test.find_one({}))
411+
docs.append(await coll.find_one({}))
410412

411413
tasks = [ConcurrentRunner(target=find_one) for _ in range(50)]
412414
for task in tasks:
413415
await task.start()
414416
for task in tasks:
415417
await task.join(10)
416418

417-
await client.test.test.delete_many({})
419+
await coll.delete_many({})
418420

419421
return len(docs), len(pool.conns)
420422

test/test_pooling.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from pymongo.errors import AutoReconnect, ConnectionFailure, DuplicateKeyError
3030
from pymongo.hello import HelloCompat
3131
from pymongo.lock import _create_lock
32+
from pymongo.read_preferences import ReadPreference
3233

3334
sys.path[0:0] = [""]
3435

@@ -395,7 +396,8 @@ def test_checkout_more_than_max_pool_size(self):
395396
pool.close()
396397

397398
def _check_maxConnecting(self, client: MongoClient, backoff=False) -> tuple[int, int]:
398-
client.test.test.insert_one({})
399+
coll = client.test.test.with_options(read_preference=ReadPreference.PRIMARY)
400+
coll.insert_one({})
399401

400402
pool = get_pool(client)
401403
if backoff:
@@ -404,15 +406,15 @@ def _check_maxConnecting(self, client: MongoClient, backoff=False) -> tuple[int,
404406

405407
# Run 50 short running operations
406408
def find_one():
407-
docs.append(client.test.test.find_one({}))
409+
docs.append(coll.find_one({}))
408410

409411
tasks = [ConcurrentRunner(target=find_one) for _ in range(50)]
410412
for task in tasks:
411413
task.start()
412414
for task in tasks:
413415
task.join(10)
414416

415-
client.test.test.delete_many({})
417+
coll.delete_many({})
416418

417419
return len(docs), len(pool.conns)
418420

0 commit comments

Comments
 (0)