1414
1515from azure_functions_worker import protos
1616from azure_functions_worker .constants import (
17+ HTTP_URI ,
1718 METADATA_PROPERTIES_WORKER_INDEXED ,
1819 PYTHON_ENABLE_DEBUG_LOGGING ,
1920 PYTHON_ENABLE_INIT_INDEXING ,
2021 PYTHON_THREADPOOL_THREAD_COUNT ,
2122 PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT ,
2223 PYTHON_THREADPOOL_THREAD_COUNT_MAX_37 ,
23- PYTHON_THREADPOOL_THREAD_COUNT_MIN , HTTP_URI , REQUIRES_ROUTE_PARAMETERS ,
24+ PYTHON_THREADPOOL_THREAD_COUNT_MIN ,
25+ REQUIRES_ROUTE_PARAMETERS
2426)
2527from azure_functions_worker .dispatcher import Dispatcher , ContextEnabledTask
2628from azure_functions_worker .version import VERSION
@@ -550,15 +552,15 @@ async def test_dispatcher_sync_threadpool_in_placeholder_above_max(self):
550552 "as the default passed is None, the cpu_count determines the "
551553 "number of max_workers and we cannot mock the os.cpu_count() "
552554 "in the concurrent.futures.ThreadPoolExecutor" )
553- class TestThreadPoolSettingsPython39 (TestThreadPoolSettingsPython38 ):
555+ class TestThreadPoolSettingsPython39 (TestThreadPoolSettingsPython37 ):
554556 def setUp (self , version = SysVersionInfo (3 , 9 , 0 , 'final' , 0 )):
555557 super (TestThreadPoolSettingsPython39 , self ).setUp (version )
556-
557558 self .mock_os_cpu = patch (
558559 'os.cpu_count' , return_value = 2 )
559560 # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
560561 self ._default_workers : Optional [int ] = 6
561562 self .mock_os_cpu .start ()
563+ self ._allowed_max_workers : int = self ._over_max_workers
562564
563565 def tearDown (self ):
564566 self .mock_os_cpu .stop ()
@@ -570,11 +572,19 @@ def tearDown(self):
570572 "as the default passed is None, the cpu_count determines the "
571573 "number of max_workers and we cannot mock the os.cpu_count() "
572574 "in the concurrent.futures.ThreadPoolExecutor" )
573- class TestThreadPoolSettingsPython310 (TestThreadPoolSettingsPython39 ):
575+ class TestThreadPoolSettingsPython310 (TestThreadPoolSettingsPython37 ):
574576 def setUp (self , version = SysVersionInfo (3 , 10 , 0 , 'final' , 0 )):
575577 super (TestThreadPoolSettingsPython310 , self ).setUp (version )
578+ self ._allowed_max_workers : int = self ._over_max_workers
579+ self .mock_os_cpu = patch (
580+ 'os.cpu_count' , return_value = 2 )
581+ # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
582+ self ._default_workers : Optional [int ] = 6
583+ self .mock_os_cpu .start ()
584+ self ._allowed_max_workers : int = self ._over_max_workers
576585
577586 def tearDown (self ):
587+ self .mock_os_cpu .stop ()
578588 super (TestThreadPoolSettingsPython310 , self ).tearDown ()
579589
580590
@@ -583,12 +593,41 @@ def tearDown(self):
583593 "as the default passed is None, the cpu_count determines the "
584594 "number of max_workers and we cannot mock the os.cpu_count() "
585595 "in the concurrent.futures.ThreadPoolExecutor" )
586- class TestThreadPoolSettingsPython311 (TestThreadPoolSettingsPython310 ):
596+ class TestThreadPoolSettingsPython311 (TestThreadPoolSettingsPython37 ):
587597 def setUp (self , version = SysVersionInfo (3 , 11 , 0 , 'final' , 0 )):
588598 super (TestThreadPoolSettingsPython311 , self ).setUp (version )
599+ self ._allowed_max_workers : int = self ._over_max_workers
600+ self .mock_os_cpu = patch (
601+ 'os.cpu_count' , return_value = 2 )
602+ # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
603+ self ._default_workers : Optional [int ] = 6
604+ self .mock_os_cpu .start ()
605+ self ._allowed_max_workers : int = self ._over_max_workers
589606
590607 def tearDown (self ):
591- super (TestThreadPoolSettingsPython310 , self ).tearDown ()
608+ self .mock_os_cpu .stop ()
609+ super (TestThreadPoolSettingsPython311 , self ).tearDown ()
610+
611+
612+ @unittest .skipIf (sys .version_info .minor != 12 ,
613+ "Run the tests only for Python 3.12. In other platforms, "
614+ "as the default passed is None, the cpu_count determines the "
615+ "number of max_workers and we cannot mock the os.cpu_count() "
616+ "in the concurrent.futures.ThreadPoolExecutor" )
617+ class TestThreadPoolSettingsPython312 (TestThreadPoolSettingsPython37 ):
618+ def setUp (self , version = SysVersionInfo (3 , 12 , 0 , 'final' , 0 )):
619+ super (TestThreadPoolSettingsPython312 , self ).setUp (version )
620+ self ._allowed_max_workers : int = self ._over_max_workers
621+ self .mock_os_cpu = patch (
622+ 'os.cpu_count' , return_value = 2 )
623+ # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
624+ self ._default_workers : Optional [int ] = 6
625+ self .mock_os_cpu .start ()
626+ self ._allowed_max_workers : int = self ._over_max_workers
627+
628+ def tearDown (self ):
629+ self .mock_os_cpu .stop ()
630+ super (TestThreadPoolSettingsPython312 , self ).tearDown ()
592631
593632
594633class TestDispatcherStein (testutils .AsyncTestCase ):
0 commit comments