From 9314515d2e506f4e0a34e1c6421ec4e8508497f9 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Mon, 1 Sep 2025 07:09:42 +0200 Subject: [PATCH 1/2] Add tests for function crashes --- tests/test_singlenodeexecutor_noblock.py | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/test_singlenodeexecutor_noblock.py b/tests/test_singlenodeexecutor_noblock.py index 0872359a..8219b256 100644 --- a/tests/test_singlenodeexecutor_noblock.py +++ b/tests/test_singlenodeexecutor_noblock.py @@ -3,6 +3,7 @@ from executorlib import SingleNodeExecutor from executorlib.standalone.serialize import cloudpickle_register +from executorlib.standalone.interactive.communication import ExecutorlibSocketError def calc(i): @@ -22,6 +23,11 @@ def init_function(): return {"a": 1, "b": 2} +def exit_funct(): + import sys + sys.exit() + + class TestExecutorBackend(unittest.TestCase): def test_meta_executor_serial_with_dependencies(self): with SingleNodeExecutor( @@ -139,4 +145,24 @@ def test_block_allocation_False_two_workers(self): ) as exe: f1_worker_id = exe.submit(get_worker_id, resource_dict={}) f2_worker_id = exe.submit(get_worker_id, resource_dict={}) - self.assertEqual(sum([f1_worker_id.result(), f2_worker_id.result()]), 0) \ No newline at end of file + self.assertEqual(sum([f1_worker_id.result(), f2_worker_id.result()]), 0) + + +class TestFunctionCrashes(unittest.TestCase): + def test_single_node_executor(self): + with self.assertRaises(ExecutorlibSocketError): + with SingleNodeExecutor() as exe: + f = exe.submit(exit_funct) + print(f.result()) + + def test_single_node_executor_block_allocation(self): + with self.assertRaises(ExecutorlibSocketError): + with SingleNodeExecutor(block_allocation=True) as exe: + f = exe.submit(exit_funct) + print(f.result()) + + def test_single_node_executor_init_function(self): + with self.assertRaises(ExecutorlibSocketError): + with SingleNodeExecutor(init_function=exit_funct, block_allocation=True) as exe: + f = exe.submit(sum, [1, 1]) + print(f.result()) From 29f6a5e981beefb69bb96f8f8ba6f04a93c5881f Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Mon, 1 Sep 2025 07:34:12 +0200 Subject: [PATCH 2/2] Update test_singlenodeexecutor_noblock.py --- tests/test_singlenodeexecutor_noblock.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_singlenodeexecutor_noblock.py b/tests/test_singlenodeexecutor_noblock.py index 8219b256..5b68aa6a 100644 --- a/tests/test_singlenodeexecutor_noblock.py +++ b/tests/test_singlenodeexecutor_noblock.py @@ -151,18 +151,18 @@ def test_block_allocation_False_two_workers(self): class TestFunctionCrashes(unittest.TestCase): def test_single_node_executor(self): with self.assertRaises(ExecutorlibSocketError): - with SingleNodeExecutor() as exe: + with SingleNodeExecutor(max_workers=2) as exe: f = exe.submit(exit_funct) print(f.result()) def test_single_node_executor_block_allocation(self): with self.assertRaises(ExecutorlibSocketError): - with SingleNodeExecutor(block_allocation=True) as exe: + with SingleNodeExecutor(max_workers=2, block_allocation=True) as exe: f = exe.submit(exit_funct) print(f.result()) def test_single_node_executor_init_function(self): with self.assertRaises(ExecutorlibSocketError): - with SingleNodeExecutor(init_function=exit_funct, block_allocation=True) as exe: + with SingleNodeExecutor(max_workers=2, init_function=exit_funct, block_allocation=True) as exe: f = exe.submit(sum, [1, 1]) print(f.result())