Skip to content

Commit ad5181b

Browse files
committed
tests: Add tests for process/thread pool executors
1 parent 08aa815 commit ad5181b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/test_executors.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import asyncio
2+
import concurrent.futures
3+
4+
from uvloop import _testbase as tb
5+
6+
7+
def fib(n):
8+
if n < 2:
9+
return 1
10+
return fib(n - 2) + fib(n - 1)
11+
12+
13+
class _TestExecutors:
14+
15+
def run_pool_test(self, pool_factory):
16+
async def run():
17+
pool = pool_factory()
18+
with pool:
19+
coros = []
20+
for i in range(0, 10):
21+
coros.append(self.loop.run_in_executor(pool, fib, i))
22+
res = await asyncio.gather(*coros, loop=self.loop)
23+
self.assertEqual(res, fib10)
24+
25+
fib10 = [fib(i) for i in range(10)]
26+
self.loop.run_until_complete(run())
27+
28+
def test_executors_process_pool_01(self):
29+
self.run_pool_test(concurrent.futures.ProcessPoolExecutor)
30+
31+
def test_executors_process_pool_02(self):
32+
self.run_pool_test(concurrent.futures.ThreadPoolExecutor)
33+
34+
35+
class TestUVExecutors(_TestExecutors, tb.UVTestCase):
36+
pass
37+
38+
39+
class TestAIOExecutors(_TestExecutors, tb.AIOTestCase):
40+
pass

0 commit comments

Comments
 (0)