15
15
"""Test the monitor module."""
16
16
from __future__ import annotations
17
17
18
+ import asyncio
18
19
import gc
19
20
import subprocess
20
21
import sys
23
24
24
25
sys .path [0 :0 ] = ["" ]
25
26
26
- from test .asynchronous import AsyncIntegrationTest , connected , unittest
27
+ from test .asynchronous import AsyncIntegrationTest , async_client_context , connected , unittest
27
28
from test .utils import (
28
29
ServerAndTopologyEventListener ,
29
30
async_wait_until ,
33
34
34
35
_IS_SYNC = False
35
36
37
+
36
38
def unregistered (ref ):
37
39
gc .collect ()
38
40
return ref not in _EXECUTORS
@@ -69,7 +71,9 @@ async def test_cleanup_executors_on_client_del(self):
69
71
del client
70
72
71
73
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
+ )
73
77
74
78
async def test_cleanup_executors_on_client_close (self ):
75
79
client = await self .create_client ()
@@ -79,12 +83,19 @@ async def test_cleanup_executors_on_client_close(self):
79
83
await client .close ()
80
84
81
85
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
+ )
83
89
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 ):
85
92
"""Test we silence noisy runtime errors fired when the AsyncMongoClient spawns a new thread
86
93
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
+ ]
88
99
completed_process : subprocess .CompletedProcess = subprocess .run (
89
100
command , capture_output = True
90
101
)
0 commit comments