Skip to content

Commit e4ac00f

Browse files
YunchuWangpeterstone2017
andauthored
add py 310 threadpoolsetting tests (#996)
* add py 310 threadpoolsetting tests Co-authored-by: peterstone2017 <[email protected]>
1 parent 2de202a commit e4ac00f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/unittests/test_dispatcher.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,30 @@ def tearDown(self):
489489
os.environ.update(self._pre_env)
490490
self.mock_os_cpu.stop()
491491
self.mock_version_info.stop()
492+
493+
494+
@unittest.skipIf(sys.version_info.minor != 10,
495+
"Run the tests only for Python 3.10. In other platforms, "
496+
"as the default passed is None, the cpu_count determines the "
497+
"number of max_workers and we cannot mock the os.cpu_count() "
498+
"in the concurrent.futures.ThreadPoolExecutor")
499+
class TestThreadPoolSettingsPython310(TestThreadPoolSettingsPython39):
500+
def setUp(self):
501+
super(TestThreadPoolSettingsPython310, self).setUp()
502+
503+
self.mock_os_cpu = patch(
504+
'os.cpu_count', return_value=2)
505+
# 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
506+
self._default_workers: Optional[int] = 6
507+
self.mock_version_info = patch(
508+
'azure_functions_worker.dispatcher.sys.version_info',
509+
SysVersionInfo(3, 10, 0, 'final', 0))
510+
511+
self.mock_os_cpu.start()
512+
self.mock_version_info.start()
513+
514+
def tearDown(self):
515+
os.environ.clear()
516+
os.environ.update(self._pre_env)
517+
self.mock_os_cpu.stop()
518+
self.mock_version_info.stop()

0 commit comments

Comments
 (0)