diff --git a/tests/unittests/test_dispatcher.py b/tests/unittests/test_dispatcher.py index 40ac6f4f7..eefa43506 100644 --- a/tests/unittests/test_dispatcher.py +++ b/tests/unittests/test_dispatcher.py @@ -489,3 +489,30 @@ def tearDown(self): os.environ.update(self._pre_env) self.mock_os_cpu.stop() self.mock_version_info.stop() + + +@unittest.skipIf(sys.version_info.minor != 10, + "Run the tests only for Python 3.10. In other platforms, " + "as the default passed is None, the cpu_count determines the " + "number of max_workers and we cannot mock the os.cpu_count() " + "in the concurrent.futures.ThreadPoolExecutor") +class TestThreadPoolSettingsPython310(TestThreadPoolSettingsPython39): + def setUp(self): + super(TestThreadPoolSettingsPython310, self).setUp() + + self.mock_os_cpu = patch( + 'os.cpu_count', return_value=2) + # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4 + self._default_workers: Optional[int] = 6 + self.mock_version_info = patch( + 'azure_functions_worker.dispatcher.sys.version_info', + SysVersionInfo(3, 10, 0, 'final', 0)) + + self.mock_os_cpu.start() + self.mock_version_info.start() + + def tearDown(self): + os.environ.clear() + os.environ.update(self._pre_env) + self.mock_os_cpu.stop() + self.mock_version_info.stop()