Skip to content

Commit 7806c30

Browse files
committed
fix tests
1 parent 2520d95 commit 7806c30

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

test/asynchronous/test_discovery_and_monitoring.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pathlib import Path
2626
from test.asynchronous.helpers import ConcurrentRunner
2727
from test.asynchronous.utils import flaky
28+
from test.utils_shared import delay
2829

2930
from pymongo.asynchronous.pool import AsyncConnection
3031
from pymongo.operations import _Op
@@ -482,15 +483,10 @@ async def teardown():
482483

483484
self.addAsyncCleanup(teardown)
484485

485-
# Seed the collection with a document for us to query with a regex.
486-
await client.test.test.delete_many({})
487-
await client.test.test.insert_one({"str0": "abcdefg"})
488-
489486
# Run a regex operation to slow down the query.
490487
async def target():
491-
query = {"str0": {"$regex": "abcd"}}
492488
try:
493-
await client.test.test.find_one(query)
489+
await client.test.test.find_one({"$where": delay(0.1)})
494490
except OperationFailure:
495491
pass
496492

@@ -499,18 +495,18 @@ async def target():
499495
for _ in range(10):
500496
tasks.append(ConcurrentRunner(target=target))
501497
for t in tasks:
502-
t.start()
498+
await t.start()
503499
for t in tasks:
504-
t.join()
500+
await t.join()
505501

506502
# Run 100 parallel operations that contend for connections.
507503
tasks = []
508504
for _ in range(100):
509505
tasks.append(ConcurrentRunner(target=target))
510506
for t in tasks:
511-
t.start()
507+
await t.start()
512508
for t in tasks:
513-
t.join()
509+
await t.join()
514510

515511
# Verify there were at least 10 connection checkout failed event but no pool cleared events.
516512
self.assertGreater(len(listener.events_by_type(ConnectionCheckOutFailedEvent)), 10)

test/test_discovery_and_monitoring.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pathlib import Path
2626
from test.helpers import ConcurrentRunner
2727
from test.utils import flaky
28+
from test.utils_shared import delay
2829

2930
from pymongo.operations import _Op
3031
from pymongo.server_selectors import writable_server_selector
@@ -476,15 +477,10 @@ def teardown():
476477

477478
self.addCleanup(teardown)
478479

479-
# Seed the collection with a document for us to query with a regex.
480-
client.test.test.delete_many({})
481-
client.test.test.insert_one({"str0": "abcdefg"})
482-
483480
# Run a regex operation to slow down the query.
484481
def target():
485-
query = {"str0": {"$regex": "abcd"}}
486482
try:
487-
client.test.test.find_one(query)
483+
client.test.test.find_one({"$where": delay(0.1)})
488484
except OperationFailure:
489485
pass
490486

0 commit comments

Comments
 (0)