Skip to content

Commit 3df3d8b

Browse files
committed
use ConcurrentRunner
1 parent 168e2fb commit 3df3d8b

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

test/asynchronous/test_server_selection_in_window.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import threading
2121
from pathlib import Path
2222
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
23+
from test.asynchronous.helpers import ConcurrentRunner
2324
from test.utils import (
2425
CMAPListener,
2526
OvertCommandListener,
@@ -97,44 +98,26 @@ def tests(self, scenario_def):
9798

9899
CustomSpecTestCreator(create_test, TestAllScenarios, TEST_PATH).create_tests()
99100

100-
if _IS_SYNC:
101-
PARENT = threading.Thread
102-
else:
103-
PARENT = object
104-
105101

106-
class FinderThread(PARENT):
102+
class FinderTask(ConcurrentRunner):
107103
def __init__(self, collection, iterations):
108104
super().__init__()
109105
self.daemon = True
110106
self.collection = collection
111107
self.iterations = iterations
112108
self.passed = False
113-
self.task = None
114109

115110
async def run(self):
116111
for _ in range(self.iterations):
117112
await self.collection.find_one({})
118113
self.passed = True
119114

120-
def start(self):
121-
if _IS_SYNC:
122-
super().start()
123-
else:
124-
self.task = asyncio.create_task(self.run())
125-
126-
async def join(self):
127-
if _IS_SYNC:
128-
super().join()
129-
else:
130-
await self.task
131-
132115

133116
class TestProse(AsyncIntegrationTest):
134117
def frequencies(self, client, listener, n_finds=10):
135118
coll = client.test.test
136119
N_TASKS = 10
137-
tasks = [FinderThread(coll, n_finds) for _ in range(N_TASKS)]
120+
tasks = [FinderTask(coll, n_finds) for _ in range(N_TASKS)]
138121
for task in tasks:
139122
task.start()
140123
for task in tasks:

test/test_server_selection_in_window.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import threading
2121
from pathlib import Path
2222
from test import IntegrationTest, client_context, unittest
23+
from test.helpers import ConcurrentRunner
2324
from test.utils import (
2425
CMAPListener,
2526
OvertCommandListener,
@@ -97,44 +98,26 @@ def tests(self, scenario_def):
9798

9899
CustomSpecTestCreator(create_test, TestAllScenarios, TEST_PATH).create_tests()
99100

100-
if _IS_SYNC:
101-
PARENT = threading.Thread
102-
else:
103-
PARENT = object
104-
105101

106-
class FinderThread(PARENT):
102+
class FinderTask(ConcurrentRunner):
107103
def __init__(self, collection, iterations):
108104
super().__init__()
109105
self.daemon = True
110106
self.collection = collection
111107
self.iterations = iterations
112108
self.passed = False
113-
self.task = None
114109

115110
def run(self):
116111
for _ in range(self.iterations):
117112
self.collection.find_one({})
118113
self.passed = True
119114

120-
def start(self):
121-
if _IS_SYNC:
122-
super().start()
123-
else:
124-
self.task = asyncio.create_task(self.run())
125-
126-
def join(self):
127-
if _IS_SYNC:
128-
super().join()
129-
else:
130-
self.task
131-
132115

133116
class TestProse(IntegrationTest):
134117
def frequencies(self, client, listener, n_finds=10):
135118
coll = client.test.test
136119
N_TASKS = 10
137-
tasks = [FinderThread(coll, n_finds) for _ in range(N_TASKS)]
120+
tasks = [FinderTask(coll, n_finds) for _ in range(N_TASKS)]
138121
for task in tasks:
139122
task.start()
140123
for task in tasks:

0 commit comments

Comments
 (0)