Skip to content

Commit 7d03e00

Browse files
committed
issue #125: add test cases
Signed-off-by: Matteo Cafasso <[email protected]>
1 parent b42bfc4 commit 7d03e00

11 files changed

Lines changed: 191 additions & 0 deletions

test/test_asynchronous_process_fork.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import unittest
77
import threading
8+
import dataclasses
89
import multiprocessing
910
from concurrent.futures import CancelledError, TimeoutError
1011

@@ -55,6 +56,16 @@ def pickling_error_decorated():
5556
return event
5657

5758

59+
@dataclasses.dataclass(frozen=True)
60+
class FrozenError(Exception):
61+
pass
62+
63+
64+
@asynchronous.process(context=mp_context)
65+
def frozen_error_decorated():
66+
raise FrozenError()
67+
68+
5869
@asynchronous.process(context=mp_context)
5970
def critical_decorated():
6071
os._exit(123)
@@ -303,6 +314,14 @@ async def test():
303314
with self.assertRaises((pickle.PicklingError, TypeError)):
304315
asyncio.run(test())
305316

317+
def test_frozen_error_decorated(self):
318+
"""Process Fork frozen errors are raised by future.result."""
319+
async def test():
320+
return await frozen_error_decorated()
321+
322+
with self.assertRaises(FrozenError):
323+
asyncio.run(test())
324+
306325
def test_timeout_decorated(self):
307326
"""Process Fork raises TimeoutError if so."""
308327
async def test():

test/test_asynchronous_process_forkserver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import unittest
77
import threading
8+
import dataclasses
89
import multiprocessing
910
from concurrent.futures import CancelledError, TimeoutError
1011

@@ -55,6 +56,16 @@ def pickling_error_decorated():
5556
return event
5657

5758

59+
@dataclasses.dataclass(frozen=True)
60+
class FrozenError(Exception):
61+
pass
62+
63+
64+
@asynchronous.process(context=mp_context)
65+
def frozen_error_decorated():
66+
raise FrozenError()
67+
68+
5869
@asynchronous.process(context=mp_context)
5970
def critical_decorated():
6071
os._exit(123)
@@ -286,6 +297,14 @@ async def test():
286297
with self.assertRaises((pickle.PicklingError, TypeError)):
287298
asyncio.run(test())
288299

300+
def test_frozen_error_decorated(self):
301+
"""Process Fork frozen errors are raised by future.result."""
302+
async def test():
303+
return await frozen_error_decorated()
304+
305+
with self.assertRaises(FrozenError):
306+
asyncio.run(test())
307+
289308
def test_timeout_decorated(self):
290309
"""Process Forkserver raises TimeoutError if so."""
291310
async def test():

test/test_asynchronous_process_spawn.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import unittest
77
import threading
8+
import dataclasses
89
import multiprocessing
910
from concurrent.futures import CancelledError, TimeoutError
1011

@@ -55,6 +56,16 @@ def pickling_error_decorated():
5556
return event
5657

5758

59+
@dataclasses.dataclass(frozen=True)
60+
class FrozenError(Exception):
61+
pass
62+
63+
64+
@asynchronous.process(context=mp_context)
65+
def frozen_error_decorated():
66+
raise FrozenError()
67+
68+
5869
@asynchronous.process(context=mp_context)
5970
def critical_decorated():
6071
os._exit(123)
@@ -286,6 +297,14 @@ async def test():
286297
with self.assertRaises((pickle.PicklingError, TypeError)):
287298
asyncio.run(test())
288299

300+
def test_frozen_error_decorated(self):
301+
"""Process Spawn frozen errors are raised by future.result."""
302+
async def test():
303+
return await frozen_error_decorated()
304+
305+
with self.assertRaises(FrozenError):
306+
asyncio.run(test())
307+
289308
def test_timeout_decorated(self):
290309
"""Process Spawn raises TimeoutError if so."""
291310
async def test():

test/test_asynchronous_thread.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import unittest
33
import threading
4+
import dataclasses
45

56
from pebble import asynchronous
67

@@ -25,6 +26,16 @@ def error_returned():
2526
return RuntimeError("BOOM!")
2627

2728

29+
@dataclasses.dataclass(frozen=True)
30+
class FrozenError(Exception):
31+
pass
32+
33+
34+
@asynchronous.thread()
35+
def frozen_error_decorated():
36+
raise FrozenError()
37+
38+
2839
@asynchronous.thread()
2940
def name_keyword_argument(name='function_kwarg'):
3041
return name
@@ -168,6 +179,14 @@ async def test():
168179
self.assertTrue(isinstance(self.exception, RuntimeError),
169180
msg=str(self.exception))
170181

182+
def test_frozen_error_decorated(self):
183+
"""Thread frozen errors are raised by future.result."""
184+
async def test():
185+
return await frozen_error_decorated()
186+
187+
with self.assertRaises(FrozenError):
188+
asyncio.run(test())
189+
171190
def test_name_keyword_argument(self):
172191
"""name keyword can be passed to a decorated function process without name """
173192
async def test():

test/test_concurrent_process_fork.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import signal
55
import unittest
66
import threading
7+
import dataclasses
78
import multiprocessing
89
from concurrent.futures import CancelledError, TimeoutError
910

@@ -54,6 +55,16 @@ def pickling_error_decorated():
5455
return event
5556

5657

58+
@dataclasses.dataclass(frozen=True)
59+
class FrozenError(Exception):
60+
pass
61+
62+
63+
@concurrent.process(context=mp_context)
64+
def frozen_error_decorated():
65+
raise FrozenError()
66+
67+
5768
@concurrent.process(context=mp_context)
5869
def critical_decorated():
5970
os._exit(123)
@@ -253,6 +264,12 @@ def test_pickling_error_decorated(self):
253264
with self.assertRaises((pickle.PicklingError, TypeError)):
254265
future.result()
255266

267+
def test_frozen_error_decorated(self):
268+
"""Process Fork frozen errors are raised by future.result."""
269+
future = frozen_error_decorated()
270+
with self.assertRaises(FrozenError):
271+
future.result()
272+
256273
def test_timeout_decorated(self):
257274
"""Process Fork raises TimeoutError if so."""
258275
future = long_decorated()

test/test_concurrent_process_forkserver.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import signal
55
import unittest
66
import threading
7+
import dataclasses
78
import multiprocessing
89
from concurrent.futures import CancelledError, TimeoutError
910

@@ -54,6 +55,16 @@ def pickling_error_decorated():
5455
return event
5556

5657

58+
@dataclasses.dataclass(frozen=True)
59+
class FrozenError(Exception):
60+
pass
61+
62+
63+
@concurrent.process(context=mp_context)
64+
def frozen_error_decorated():
65+
raise FrozenError()
66+
67+
5768
@concurrent.process(context=mp_context)
5869
def critical_decorated():
5970
os._exit(123)
@@ -214,6 +225,12 @@ def test_pickling_error_decorated(self):
214225
with self.assertRaises((pickle.PicklingError, TypeError)):
215226
future.result()
216227

228+
def test_frozen_error_decorated(self):
229+
"""Process Fork frozen errors are raised by future.result."""
230+
future = frozen_error_decorated()
231+
with self.assertRaises(FrozenError):
232+
future.result()
233+
217234
def test_timeout_decorated(self):
218235
"""Process Forkserver raises TimeoutError if so."""
219236
future = long_decorated()

test/test_concurrent_process_spawn.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import signal
55
import unittest
66
import threading
7+
import dataclasses
78
import multiprocessing
89
from concurrent.futures import CancelledError, TimeoutError
910

@@ -54,6 +55,16 @@ def pickling_error_decorated():
5455
return event
5556

5657

58+
@dataclasses.dataclass(frozen=True)
59+
class FrozenError(Exception):
60+
pass
61+
62+
63+
@concurrent.process(context=mp_context)
64+
def frozen_error_decorated():
65+
raise FrozenError()
66+
67+
5768
@concurrent.process(context=mp_context)
5869
def critical_decorated():
5970
os._exit(123)
@@ -214,6 +225,12 @@ def test_pickling_error_decorated(self):
214225
with self.assertRaises((pickle.PicklingError, TypeError)):
215226
future.result()
216227

228+
def test_error_decorated(self):
229+
"""Process Fork errors are raised by future.result."""
230+
future = error_decorated()
231+
with self.assertRaises(RuntimeError):
232+
future.result()
233+
217234
def test_timeout_decorated(self):
218235
"""Process Spawn raises TimeoutError if so."""
219236
future = long_decorated()

test/test_process_pool_fork.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import asyncio
77
import unittest
88
import threading
9+
import dataclasses
910
import multiprocessing
1011

1112
from concurrent.futures import CancelledError, TimeoutError
@@ -64,6 +65,15 @@ def return_error_function():
6465
return BaseException("BOOM!")
6566

6667

68+
@dataclasses.dataclass(frozen=True)
69+
class FrozenError(Exception):
70+
pass
71+
72+
73+
def frozen_error_function():
74+
raise FrozenError()
75+
76+
6777
def pickle_error_function():
6878
return threading.Lock()
6979

@@ -187,6 +197,12 @@ def test_process_pool_pickling_error_result(self):
187197
future = pool.schedule(pickle_error_function)
188198
self.assertRaises((pickle.PicklingError, TypeError), future.result)
189199

200+
def test_process_pool_frozen_error(self):
201+
"""Process Pool Fork frozen errors are raised by future get."""
202+
with ProcessPool(max_workers=1, context=mp_context) as pool:
203+
future = pool.schedule(frozen_error_function)
204+
self.assertRaises(FrozenError, future.result)
205+
190206
def test_process_pool_timeout(self):
191207
"""Process Pool Fork future raises TimeoutError if so."""
192208
with ProcessPool(max_workers=1, context=mp_context) as pool:

test/test_process_pool_forkserver.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import asyncio
77
import unittest
88
import threading
9+
import dataclasses
910
import multiprocessing
1011

1112
from concurrent.futures import CancelledError, TimeoutError
@@ -70,6 +71,15 @@ def pickle_error_function():
7071
return threading.Lock()
7172

7273

74+
@dataclasses.dataclass(frozen=True)
75+
class FrozenError(Exception):
76+
pass
77+
78+
79+
def frozen_error_function():
80+
raise FrozenError()
81+
82+
7383
def long_function(value=1):
7484
time.sleep(value)
7585
return value
@@ -189,6 +199,12 @@ def test_process_pool_pickling_error_result(self):
189199
future = pool.schedule(pickle_error_function)
190200
self.assertRaises((pickle.PicklingError, TypeError), future.result)
191201

202+
def test_process_pool_frozen_error(self):
203+
"""Process Pool Forkserver frozen errors are raised by future get."""
204+
with ProcessPool(max_workers=1, context=mp_context) as pool:
205+
future = pool.schedule(frozen_error_function)
206+
self.assertRaises(FrozenError, future.result)
207+
192208
def test_process_pool_timeout(self):
193209
"""Process Pool Forkserver future raises TimeoutError if so."""
194210
with ProcessPool(max_workers=1, context=mp_context) as pool:

test/test_process_pool_spawn.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import asyncio
77
import unittest
88
import threading
9+
import dataclasses
910
import multiprocessing
1011

1112
from concurrent.futures import CancelledError, TimeoutError
@@ -68,6 +69,15 @@ def pickle_error_function():
6869
return threading.Lock()
6970

7071

72+
@dataclasses.dataclass(frozen=True)
73+
class FrozenError(Exception):
74+
pass
75+
76+
77+
def frozen_error_function():
78+
raise FrozenError()
79+
80+
7181
def long_function(value=1):
7282
time.sleep(value)
7383
return value
@@ -187,6 +197,12 @@ def test_process_pool_pickling_error_result(self):
187197
future = pool.schedule(pickle_error_function)
188198
self.assertRaises((pickle.PicklingError, TypeError), future.result)
189199

200+
def test_process_pool_frozen_error(self):
201+
"""Process Pool Spawn frozen errors are raised by future get."""
202+
with ProcessPool(max_workers=1, context=mp_context) as pool:
203+
future = pool.schedule(frozen_error_function)
204+
self.assertRaises(FrozenError, future.result)
205+
190206
def test_process_pool_timeout(self):
191207
"""Process Pool Spawn future raises TimeoutError if so."""
192208
with ProcessPool(max_workers=1, context=mp_context) as pool:

0 commit comments

Comments
 (0)