@@ -59,32 +59,48 @@ def test_run_single_creates_client_and_calls_bootstrap(
5959 mock_bootstrap .run .assert_called_once_with ("h.fn" , mock_client )
6060
6161 @patch .object (MultiConcurrentRunner , "_emit_worker_pool_event" )
62- @patch ("multiprocessing.Process " )
63- def test_run_concurrent_spawns_and_joins (self , mock_process , mock_emit ):
62+ @patch ("multiprocessing.get_context " )
63+ def test_run_concurrent_spawns_and_joins (self , mock_get_context , mock_emit ):
6464 fake_proc = MagicMock ()
65- mock_process .return_value = fake_proc
65+ mock_ctx = MagicMock ()
66+ mock_ctx .Process .return_value = fake_proc
67+ mock_get_context .return_value = mock_ctx
6668
6769 MultiConcurrentRunner .run_concurrent (
6870 "h" , "a" , False , "/sock" , max_concurrency = 3
6971 )
7072
71- self .assertEqual (mock_process .call_count , 3 )
73+ self .assertEqual (mock_ctx . Process .call_count , 3 )
7274 self .assertEqual (fake_proc .start .call_count , 3 )
7375 self .assertEqual (fake_proc .join .call_count , 3 )
7476
75- for call_args in mock_process .call_args_list :
77+ for call_args in mock_ctx . Process .call_args_list :
7678 target = call_args .kwargs .get ("target" ) or call_args [1 ].get ("target" )
7779 args = call_args .kwargs .get ("args" ) or call_args [1 ].get ("args" )
7880 self .assertEqual (target , MultiConcurrentRunner .run_single )
7981 self .assertEqual (args , ("h" , "a" , False , "/sock" ))
8082
81- @patch ("multiprocessing.Process" )
83+ @patch .object (MultiConcurrentRunner , "_emit_worker_pool_event" )
84+ @patch ("multiprocessing.get_context" )
85+ def test_run_concurrent_pins_fork_start_method (self , mock_get_context , mock_emit ):
86+ mock_ctx = MagicMock ()
87+ mock_get_context .return_value = mock_ctx
88+
89+ MultiConcurrentRunner .run_concurrent (
90+ "h" , "a" , False , "/sock" , max_concurrency = 2
91+ )
92+
93+ mock_get_context .assert_called_once_with ("fork" )
94+ self .assertEqual (mock_ctx .Process .call_count , 2 )
95+
96+ @patch ("multiprocessing.get_context" )
8297 def test_run_concurrent_emits_worker_pool_event_once_before_spawning (
83- self , mock_process
98+ self , mock_get_context
8499 ):
85- mock_process .return_value = MagicMock ()
100+ mock_ctx = MagicMock ()
101+ mock_get_context .return_value = mock_ctx
86102 order_tracker = MagicMock ()
87- order_tracker .attach_mock (mock_process , "process" )
103+ order_tracker .attach_mock (mock_ctx . Process , "process" )
88104
89105 with patch .object (
90106 MultiConcurrentRunner , "_emit_worker_pool_event"
0 commit comments