From 89c355aed3ba7e91a3aeadc19aa3be76a04d58de Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Mon, 3 Mar 2025 12:01:40 -0800 Subject: [PATCH] Try to fix transiency of test_force_shutdown_workers On some platforms we seem to get 255 instead of -SIGNAL, so instead use mocks to know we called the correct method --- .../test_concurrent_futures/test_process_pool.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_concurrent_futures/test_process_pool.py b/Lib/test/test_concurrent_futures/test_process_pool.py index 354b7d0a346970..ae4b00b5a5fe0f 100644 --- a/Lib/test/test_concurrent_futures/test_process_pool.py +++ b/Lib/test/test_concurrent_futures/test_process_pool.py @@ -270,15 +270,18 @@ def test_force_shutdown_workers(self, function_name): self.assertEqual(q.get(timeout=5), 'started') worker_process = list(executor._processes.values())[0] + + Mock = unittest.mock.Mock + worker_process.terminate = Mock(wraps=worker_process.terminate) + worker_process.kill = Mock(wraps=worker_process.kill) + getattr(executor, function_name)() worker_process.join() - if function_name == TERMINATE_WORKERS or \ - sys.platform == 'win32': - # On windows, kill and terminate both send SIGTERM - self.assertEqual(worker_process.exitcode, -signal.SIGTERM) + if function_name == TERMINATE_WORKERS: + worker_process.terminate.assert_called() elif function_name == KILL_WORKERS: - self.assertEqual(worker_process.exitcode, -signal.SIGKILL) + worker_process.kill.assert_called() else: self.fail(f"Unknown operation: {function_name}")