File tree Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Original file line number Diff line number Diff line change 2525from pathlib import Path
2626from test .asynchronous .helpers import ConcurrentRunner
2727from test .asynchronous .utils import flaky
28+ from test .utils_shared import delay
2829
2930from pymongo .asynchronous .pool import AsyncConnection
3031from 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 )
Original file line number Diff line number Diff line change 2525from pathlib import Path
2626from test .helpers import ConcurrentRunner
2727from test .utils import flaky
28+ from test .utils_shared import delay
2829
2930from pymongo .operations import _Op
3031from 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
You can’t perform that action at this time.
0 commit comments