Skip to content

Commit f04eb36

Browse files
authored
Merge branch 'master' into PYTHON-5100
2 parents ecb237d + 8ae9a04 commit f04eb36

24 files changed

+1894
-81
lines changed

test/asynchronous/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,15 +1176,15 @@ def unmanaged_simple_client(
11761176

11771177
async def disable_replication(self, client):
11781178
"""Disable replication on all secondaries."""
1179-
for h, p in client.secondaries:
1179+
for h, p in await client.secondaries:
11801180
secondary = await self.async_single_client(h, p)
1181-
secondary.admin.command("configureFailPoint", "stopReplProducer", mode="alwaysOn")
1181+
await secondary.admin.command("configureFailPoint", "stopReplProducer", mode="alwaysOn")
11821182

11831183
async def enable_replication(self, client):
11841184
"""Enable replication on all secondaries."""
1185-
for h, p in client.secondaries:
1185+
for h, p in await client.secondaries:
11861186
secondary = await self.async_single_client(h, p)
1187-
secondary.admin.command("configureFailPoint", "stopReplProducer", mode="off")
1187+
await secondary.admin.command("configureFailPoint", "stopReplProducer", mode="off")
11881188

11891189

11901190
class AsyncUnitTest(AsyncPyMongoTestCase):

test/asynchronous/helpers.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Shared constants and helper methods for pymongo, bson, and gridfs test suites."""
1616
from __future__ import annotations
1717

18+
import asyncio
1819
import base64
1920
import gc
2021
import multiprocessing
@@ -30,6 +31,8 @@
3031
import warnings
3132
from asyncio import iscoroutinefunction
3233

34+
from pymongo._asyncio_task import create_task
35+
3336
try:
3437
import ipaddress
3538

@@ -369,3 +372,37 @@ def disable(self):
369372
os.environ.pop("SSL_CERT_FILE")
370373
else:
371374
os.environ["SSL_CERT_FILE"] = self.original_certs
375+
376+
377+
if _IS_SYNC:
378+
PARENT = threading.Thread
379+
else:
380+
PARENT = object
381+
382+
383+
class ConcurrentRunner(PARENT):
384+
def __init__(self, name, *args, **kwargs):
385+
if _IS_SYNC:
386+
super().__init__(*args, **kwargs)
387+
self.name = name
388+
self.stopped = False
389+
self.task = None
390+
if "target" in kwargs:
391+
self.target = kwargs["target"]
392+
393+
if not _IS_SYNC:
394+
395+
async def start(self):
396+
self.task = create_task(self.run(), name=self.name)
397+
398+
async def join(self, timeout: float | None = 0): # type: ignore[override]
399+
if self.task is not None:
400+
await asyncio.wait([self.task], timeout=timeout)
401+
402+
def is_alive(self):
403+
return not self.stopped
404+
405+
async def run(self):
406+
if self.target:
407+
await self.target()
408+
self.stopped = True

0 commit comments

Comments
 (0)