Skip to content

Commit

Permalink
asynchronous/process: add pool parameter tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
  • Loading branch information
noxdafox committed Sep 29, 2024
1 parent 2c39b74 commit d02d231
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
14 changes: 13 additions & 1 deletion test/test_asynchronous_process_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()))
14 changes: 13 additions & 1 deletion test/test_asynchronous_process_forkserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()))
14 changes: 13 additions & 1 deletion test/test_asynchronous_process_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()))

0 comments on commit d02d231

Please sign in to comment.