Skip to content

Commit 5b186a6

Browse files
fix: cover join_or_terminate states
* [TEST] Add comprehensive tests for join_or_terminate in ParallelWorkerPool This commit adds `test_join_or_terminate_mixed_states` and `test_join_or_terminate_empty` to `tests/test_parallel_processor.py`. These tests verify the emergency shutdown mechanism in scenarios with multiple processes in different states (hanging, clean exit) and when the process list is empty. Co-authored-by: n24q02m <135627235+n24q02m@users.noreply.github.com> * [TEST] Add comprehensive tests for join_or_terminate in ParallelWorkerPool This commit adds `test_join_or_terminate_mixed_states` and `test_join_or_terminate_empty` to `tests/test_parallel_processor.py`. These tests verify the emergency shutdown mechanism in scenarios with multiple processes in different states (hanging, clean exit) and when the process list is empty. Also fixed a formatting issue in `tests/test_parallel_processor.py` flagged by CI. Co-authored-by: n24q02m <135627235+n24q02m@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 0a07dad commit 5b186a6

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_parallel_processor.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,45 @@ def test_process_stream_error_signal():
560560
list(pool._process_stream([1]))
561561

562562
pool.join_or_terminate.assert_called_once()
563+
564+
565+
def test_join_or_terminate_mixed_states():
566+
"""Test join_or_terminate with multiple processes in different states."""
567+
pool = ParallelWorkerPool(worker=SquareWorker, config=PoolConfig(num_workers=3))
568+
569+
# P1: Finishes immediately
570+
p1 = MagicMock()
571+
p1.is_alive.return_value = False
572+
573+
# P2: Hangs and needs termination
574+
p2 = MagicMock()
575+
p2.is_alive.return_value = True
576+
577+
# P3: Also hangs
578+
p3 = MagicMock()
579+
p3.is_alive.return_value = True
580+
581+
pool.processes = [p1, p2, p3]
582+
583+
pool.join_or_terminate(timeout=0.1)
584+
585+
# P1 should have been joined but not terminated
586+
p1.join.assert_called_once_with(timeout=0.1)
587+
p1.terminate.assert_not_called()
588+
589+
# P2 and P3 should have been joined AND terminated
590+
p2.join.assert_called_once_with(timeout=0.1)
591+
p2.terminate.assert_called_once()
592+
p3.join.assert_called_once_with(timeout=0.1)
593+
p3.terminate.assert_called_once()
594+
595+
# Processes list should be cleared
596+
assert pool.processes == []
597+
598+
599+
def test_join_or_terminate_empty():
600+
"""Test join_or_terminate with no processes."""
601+
pool = ParallelWorkerPool(worker=SquareWorker, config=PoolConfig(num_workers=0))
602+
pool.processes = []
603+
pool.join_or_terminate()
604+
assert pool.processes == []

0 commit comments

Comments
 (0)