File tree Expand file tree Collapse file tree 4 files changed +76
-66
lines changed Expand file tree Collapse file tree 4 files changed +76
-66
lines changed Original file line number Diff line number Diff line change 15
15
"""Shared constants and helper methods for pymongo, bson, and gridfs test suites."""
16
16
from __future__ import annotations
17
17
18
+ import asyncio
18
19
import base64
19
20
import gc
20
21
import multiprocessing
30
31
import warnings
31
32
from asyncio import iscoroutinefunction
32
33
34
+ from pymongo ._asyncio_task import create_task
35
+
33
36
try :
34
37
import ipaddress
35
38
@@ -369,3 +372,37 @@ def disable(self):
369
372
os .environ .pop ("SSL_CERT_FILE" )
370
373
else :
371
374
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
Original file line number Diff line number Diff line change 18
18
import asyncio
19
19
import functools
20
20
import os
21
- import threading
22
21
import unittest
23
22
from asyncio import iscoroutinefunction
24
23
from collections import abc
25
24
from test .asynchronous import AsyncIntegrationTest , async_client_context , client_knobs
25
+ from test .asynchronous .helpers import ConcurrentRunner
26
26
from test .utils import (
27
27
CMAPListener ,
28
28
CompareType ,
55
55
56
56
_IS_SYNC = False
57
57
58
- if _IS_SYNC :
59
- PARENT = threading .Thread
60
- else :
61
- PARENT = object
62
-
63
-
64
- class ConcurrentRunner (PARENT ):
65
- def __init__ (self , name , * args , ** kwargs ):
66
- if _IS_SYNC :
67
- super ().__init__ (* args , ** kwargs )
68
- self .name = name
69
- self .stopped = False
70
- self .task = None
71
- if "target" in kwargs :
72
- self .target = kwargs ["target" ]
73
-
74
- if not _IS_SYNC :
75
-
76
- async def start (self ):
77
- self .task = asyncio .create_task (self .run (), name = self .name )
78
-
79
- async def join (self , timeout : float | None = 0 ): # type: ignore[override]
80
- if self .task is not None :
81
- await asyncio .wait ([self .task ], timeout = timeout )
82
-
83
- def is_alive (self ):
84
- return not self .stopped
85
-
86
- async def run (self ):
87
- if self .target :
88
- await self .target ()
89
-
90
58
91
59
class SpecRunnerTask (ConcurrentRunner ):
92
60
def __init__ (self , name ):
Original file line number Diff line number Diff line change 15
15
"""Shared constants and helper methods for pymongo, bson, and gridfs test suites."""
16
16
from __future__ import annotations
17
17
18
+ import asyncio
18
19
import base64
19
20
import gc
20
21
import multiprocessing
30
31
import warnings
31
32
from asyncio import iscoroutinefunction
32
33
34
+ from pymongo ._asyncio_task import create_task
35
+
33
36
try :
34
37
import ipaddress
35
38
@@ -369,3 +372,37 @@ def disable(self):
369
372
os .environ .pop ("SSL_CERT_FILE" )
370
373
else :
371
374
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
+ def start (self ):
396
+ self .task = create_task (self .run (), name = self .name )
397
+
398
+ def join (self , timeout : float | None = 0 ): # type: ignore[override]
399
+ if self .task is not None :
400
+ asyncio .wait ([self .task ], timeout = timeout )
401
+
402
+ def is_alive (self ):
403
+ return not self .stopped
404
+
405
+ def run (self ):
406
+ if self .target :
407
+ self .target ()
408
+ self .stopped = True
Original file line number Diff line number Diff line change 18
18
import asyncio
19
19
import functools
20
20
import os
21
- import threading
22
21
import unittest
23
22
from asyncio import iscoroutinefunction
24
23
from collections import abc
25
24
from test import IntegrationTest , client_context , client_knobs
25
+ from test .helpers import ConcurrentRunner
26
26
from test .utils import (
27
27
CMAPListener ,
28
28
CompareType ,
55
55
56
56
_IS_SYNC = True
57
57
58
- if _IS_SYNC :
59
- PARENT = threading .Thread
60
- else :
61
- PARENT = object
62
-
63
-
64
- class ConcurrentRunner (PARENT ):
65
- def __init__ (self , name , * args , ** kwargs ):
66
- if _IS_SYNC :
67
- super ().__init__ (* args , ** kwargs )
68
- self .name = name
69
- self .stopped = False
70
- self .task = None
71
- if "target" in kwargs :
72
- self .target = kwargs ["target" ]
73
-
74
- if not _IS_SYNC :
75
-
76
- def start (self ):
77
- self .task = asyncio .create_task (self .run (), name = self .name )
78
-
79
- def join (self , timeout : float | None = 0 ): # type: ignore[override]
80
- if self .task is not None :
81
- asyncio .wait ([self .task ], timeout = timeout )
82
-
83
- def is_alive (self ):
84
- return not self .stopped
85
-
86
- def run (self ):
87
- if self .target :
88
- self .target ()
89
-
90
58
91
59
class SpecRunnerThread (ConcurrentRunner ):
92
60
def __init__ (self , name ):
You can’t perform that action at this time.
0 commit comments