Skip to content

Commit 16943a4

Browse files
committed
edit test to require sync
1 parent b337ba0 commit 16943a4

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

test/asynchronous/test_monitor.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Test the monitor module."""
1616
from __future__ import annotations
1717

18+
import asyncio
1819
import gc
1920
import subprocess
2021
import sys
@@ -23,7 +24,7 @@
2324

2425
sys.path[0:0] = [""]
2526

26-
from test.asynchronous import AsyncIntegrationTest, connected, unittest
27+
from test.asynchronous import AsyncIntegrationTest, async_client_context, connected, unittest
2728
from test.utils import (
2829
ServerAndTopologyEventListener,
2930
async_wait_until,
@@ -33,6 +34,7 @@
3334

3435
_IS_SYNC = False
3536

37+
3638
def unregistered(ref):
3739
gc.collect()
3840
return ref not in _EXECUTORS
@@ -69,7 +71,9 @@ async def test_cleanup_executors_on_client_del(self):
6971
del client
7072

7173
for ref, name in executor_refs:
72-
await async_wait_until(partial(unregistered, ref), f"unregister executor: {name}", timeout=5)
74+
await async_wait_until(
75+
partial(unregistered, ref), f"unregister executor: {name}", timeout=5
76+
)
7377

7478
async def test_cleanup_executors_on_client_close(self):
7579
client = await self.create_client()
@@ -79,12 +83,19 @@ async def test_cleanup_executors_on_client_close(self):
7983
await client.close()
8084

8185
for executor in executors:
82-
await async_wait_until(lambda: executor._stopped, f"closed executor: {executor._name}", timeout=5)
86+
await async_wait_until(
87+
lambda: executor._stopped, f"closed executor: {executor._name}", timeout=5
88+
)
8389

84-
async def test_no_thread_start_runtime_err_on_shutdown(self):
90+
@async_client_context.require_sync
91+
def test_no_thread_start_runtime_err_on_shutdown(self):
8592
"""Test we silence noisy runtime errors fired when the AsyncMongoClient spawns a new thread
8693
on process shutdown."""
87-
command = [sys.executable, "-c", "from pymongo import AsyncMongoClient; c = AsyncMongoClient()"]
94+
command = [
95+
sys.executable,
96+
"-c",
97+
"from pymongo import AsyncMongoClient; c = AsyncMongoClient()",
98+
]
8899
completed_process: subprocess.CompletedProcess = subprocess.run(
89100
command, capture_output=True
90101
)

test/test_monitor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Test the monitor module."""
1616
from __future__ import annotations
1717

18+
import asyncio
1819
import gc
1920
import subprocess
2021
import sys
@@ -23,7 +24,7 @@
2324

2425
sys.path[0:0] = [""]
2526

26-
from test import IntegrationTest, connected, unittest
27+
from test import IntegrationTest, client_context, connected, unittest
2728
from test.utils import (
2829
ServerAndTopologyEventListener,
2930
wait_until,
@@ -33,6 +34,7 @@
3334

3435
_IS_SYNC = True
3536

37+
3638
def unregistered(ref):
3739
gc.collect()
3840
return ref not in _EXECUTORS
@@ -81,6 +83,7 @@ def test_cleanup_executors_on_client_close(self):
8183
for executor in executors:
8284
wait_until(lambda: executor._stopped, f"closed executor: {executor._name}", timeout=5)
8385

86+
@client_context.require_sync
8487
def test_no_thread_start_runtime_err_on_shutdown(self):
8588
"""Test we silence noisy runtime errors fired when the MongoClient spawns a new thread
8689
on process shutdown."""

0 commit comments

Comments
 (0)