From d02d23108182cdd5427d1ececc7a11e0220a01e7 Mon Sep 17 00:00:00 2001 From: Matteo Cafasso Date: Sun, 29 Sep 2024 23:35:13 +0300 Subject: [PATCH] asynchronous/process: add `pool` parameter tests Signed-off-by: Matteo Cafasso --- test/test_asynchronous_process_fork.py | 14 +++++++++++++- test/test_asynchronous_process_forkserver.py | 14 +++++++++++++- test/test_asynchronous_process_spawn.py | 14 +++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/test/test_asynchronous_process_fork.py b/test/test_asynchronous_process_fork.py index e016dd4..6b73632 100644 --- a/test/test_asynchronous_process_fork.py +++ b/test/test_asynchronous_process_fork.py @@ -9,7 +9,7 @@ import multiprocessing from concurrent.futures import CancelledError, TimeoutError -from pebble import asynchronous, ProcessExpired +from pebble import asynchronous, ProcessExpired, ProcessPool # set start method @@ -107,6 +107,11 @@ def daemon_keyword_decorated(): return multiprocessing.current_process().daemon +@asynchronous.process(pool=ProcessPool(1, context=mp_context)) +def pool_decorated(_argument, _keyword_argument=0): + return multiprocessing.current_process().pid + + class ProcessAsynchronousObj: a = 0 @@ -431,3 +436,10 @@ async def test(): return await callable_object(1) self.assertEqual(asyncio.run(test()), 1) + + def test_pool_decorated(self): + """Process Fork results are produced.""" + async def test(): + return await pool_decorated(1, 1) + + self.assertEqual(asyncio.run(test()), asyncio.run(test())) diff --git a/test/test_asynchronous_process_forkserver.py b/test/test_asynchronous_process_forkserver.py index 5ec549a..abffb65 100644 --- a/test/test_asynchronous_process_forkserver.py +++ b/test/test_asynchronous_process_forkserver.py @@ -9,7 +9,7 @@ import multiprocessing from concurrent.futures import CancelledError, TimeoutError -from pebble import asynchronous, ProcessExpired +from pebble import asynchronous, ProcessExpired, ProcessPool # set start method @@ -107,6 +107,11 @@ def daemon_keyword_decorated(): return multiprocessing.current_process().daemon +@asynchronous.process(pool=ProcessPool(1, context=mp_context)) +def pool_decorated(_argument, _keyword_argument=0): + return multiprocessing.current_process().pid + + class ProcessAsynchronousObj: a = 0 @@ -404,3 +409,10 @@ async def test(): return await callable_object(1) self.assertEqual(asyncio.run(test()), 1) + + def test_pool_decorated(self): + """Process Forkserver results are produced.""" + async def test(): + return await pool_decorated(1, 1) + + self.assertEqual(asyncio.run(test()), asyncio.run(test())) diff --git a/test/test_asynchronous_process_spawn.py b/test/test_asynchronous_process_spawn.py index 73b7e72..a9b8baf 100644 --- a/test/test_asynchronous_process_spawn.py +++ b/test/test_asynchronous_process_spawn.py @@ -9,7 +9,7 @@ import multiprocessing from concurrent.futures import CancelledError, TimeoutError -from pebble import asynchronous, ProcessExpired +from pebble import asynchronous, ProcessExpired, ProcessPool # set start method @@ -107,6 +107,11 @@ def daemon_keyword_decorated(): return multiprocessing.current_process().daemon +@asynchronous.process(pool=ProcessPool(1, context=mp_context)) +def pool_decorated(_argument, _keyword_argument=0): + return multiprocessing.current_process().pid + + class ProcessAsynchronousObj: a = 0 @@ -404,3 +409,10 @@ async def test(): return await callable_object(1) self.assertEqual(asyncio.run(test()), 1) + + def test_pool_decorated(self): + """Process Spawn results are produced.""" + async def test(): + return await pool_decorated(1, 1) + + self.assertEqual(asyncio.run(test()), asyncio.run(test()))