14
14
15
15
from azure_functions_worker import protos
16
16
from azure_functions_worker .constants import (
17
+ HTTP_URI ,
17
18
METADATA_PROPERTIES_WORKER_INDEXED ,
18
19
PYTHON_ENABLE_DEBUG_LOGGING ,
19
20
PYTHON_ENABLE_INIT_INDEXING ,
20
21
PYTHON_THREADPOOL_THREAD_COUNT ,
21
22
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT ,
22
23
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
24
26
)
25
27
from azure_functions_worker .dispatcher import Dispatcher , ContextEnabledTask
26
28
from azure_functions_worker .utils .config_manager import config_manager
@@ -552,15 +554,15 @@ async def test_dispatcher_sync_threadpool_in_placeholder_above_max(self):
552
554
"as the default passed is None, the cpu_count determines the "
553
555
"number of max_workers and we cannot mock the os.cpu_count() "
554
556
"in the concurrent.futures.ThreadPoolExecutor" )
555
- class TestThreadPoolSettingsPython39 (TestThreadPoolSettingsPython38 ):
557
+ class TestThreadPoolSettingsPython39 (TestThreadPoolSettingsPython37 ):
556
558
def setUp (self , version = SysVersionInfo (3 , 9 , 0 , 'final' , 0 )):
557
559
super (TestThreadPoolSettingsPython39 , self ).setUp (version )
558
-
559
560
self .mock_os_cpu = patch (
560
561
'os.cpu_count' , return_value = 2 )
561
562
# 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
562
563
self ._default_workers : Optional [int ] = 6
563
564
self .mock_os_cpu .start ()
565
+ self ._allowed_max_workers : int = self ._over_max_workers
564
566
565
567
def tearDown (self ):
566
568
self .mock_os_cpu .stop ()
@@ -572,11 +574,19 @@ def tearDown(self):
572
574
"as the default passed is None, the cpu_count determines the "
573
575
"number of max_workers and we cannot mock the os.cpu_count() "
574
576
"in the concurrent.futures.ThreadPoolExecutor" )
575
- class TestThreadPoolSettingsPython310 (TestThreadPoolSettingsPython39 ):
577
+ class TestThreadPoolSettingsPython310 (TestThreadPoolSettingsPython37 ):
576
578
def setUp (self , version = SysVersionInfo (3 , 10 , 0 , 'final' , 0 )):
577
579
super (TestThreadPoolSettingsPython310 , self ).setUp (version )
580
+ self ._allowed_max_workers : int = self ._over_max_workers
581
+ self .mock_os_cpu = patch (
582
+ 'os.cpu_count' , return_value = 2 )
583
+ # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
584
+ self ._default_workers : Optional [int ] = 6
585
+ self .mock_os_cpu .start ()
586
+ self ._allowed_max_workers : int = self ._over_max_workers
578
587
579
588
def tearDown (self ):
589
+ self .mock_os_cpu .stop ()
580
590
super (TestThreadPoolSettingsPython310 , self ).tearDown ()
581
591
582
592
@@ -585,12 +595,41 @@ def tearDown(self):
585
595
"as the default passed is None, the cpu_count determines the "
586
596
"number of max_workers and we cannot mock the os.cpu_count() "
587
597
"in the concurrent.futures.ThreadPoolExecutor" )
588
- class TestThreadPoolSettingsPython311 (TestThreadPoolSettingsPython310 ):
598
+ class TestThreadPoolSettingsPython311 (TestThreadPoolSettingsPython37 ):
589
599
def setUp (self , version = SysVersionInfo (3 , 11 , 0 , 'final' , 0 )):
590
600
super (TestThreadPoolSettingsPython311 , self ).setUp (version )
601
+ self ._allowed_max_workers : int = self ._over_max_workers
602
+ self .mock_os_cpu = patch (
603
+ 'os.cpu_count' , return_value = 2 )
604
+ # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
605
+ self ._default_workers : Optional [int ] = 6
606
+ self .mock_os_cpu .start ()
607
+ self ._allowed_max_workers : int = self ._over_max_workers
591
608
592
609
def tearDown (self ):
593
- super (TestThreadPoolSettingsPython310 , self ).tearDown ()
610
+ self .mock_os_cpu .stop ()
611
+ super (TestThreadPoolSettingsPython311 , self ).tearDown ()
612
+
613
+
614
+ @unittest .skipIf (sys .version_info .minor != 12 ,
615
+ "Run the tests only for Python 3.12. In other platforms, "
616
+ "as the default passed is None, the cpu_count determines the "
617
+ "number of max_workers and we cannot mock the os.cpu_count() "
618
+ "in the concurrent.futures.ThreadPoolExecutor" )
619
+ class TestThreadPoolSettingsPython312 (TestThreadPoolSettingsPython37 ):
620
+ def setUp (self , version = SysVersionInfo (3 , 12 , 0 , 'final' , 0 )):
621
+ super (TestThreadPoolSettingsPython312 , self ).setUp (version )
622
+ self ._allowed_max_workers : int = self ._over_max_workers
623
+ self .mock_os_cpu = patch (
624
+ 'os.cpu_count' , return_value = 2 )
625
+ # 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
626
+ self ._default_workers : Optional [int ] = 6
627
+ self .mock_os_cpu .start ()
628
+ self ._allowed_max_workers : int = self ._over_max_workers
629
+
630
+ def tearDown (self ):
631
+ self .mock_os_cpu .stop ()
632
+ super (TestThreadPoolSettingsPython312 , self ).tearDown ()
594
633
595
634
596
635
class TestDispatcherStein (testutils .AsyncTestCase ):
0 commit comments