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 .version import VERSION
@@ -550,15 +552,15 @@ async def test_dispatcher_sync_threadpool_in_placeholder_above_max(self):
550
552
"as the default passed is None, the cpu_count determines the "
551
553
"number of max_workers and we cannot mock the os.cpu_count() "
552
554
"in the concurrent.futures.ThreadPoolExecutor" )
553
- class TestThreadPoolSettingsPython39 (TestThreadPoolSettingsPython38 ):
555
+ class TestThreadPoolSettingsPython39 (TestThreadPoolSettingsPython37 ):
554
556
def setUp (self , version = SysVersionInfo (3 , 9 , 0 , 'final' , 0 )):
555
557
super (TestThreadPoolSettingsPython39 , self ).setUp (version )
556
-
557
558
self .mock_os_cpu = patch (
558
559
'os.cpu_count' , return_value = 2 )
559
560
# 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
560
561
self ._default_workers : Optional [int ] = 6
561
562
self .mock_os_cpu .start ()
563
+ self ._allowed_max_workers : int = self ._over_max_workers
562
564
563
565
def tearDown (self ):
564
566
self .mock_os_cpu .stop ()
@@ -570,11 +572,19 @@ def tearDown(self):
570
572
"as the default passed is None, the cpu_count determines the "
571
573
"number of max_workers and we cannot mock the os.cpu_count() "
572
574
"in the concurrent.futures.ThreadPoolExecutor" )
573
- class TestThreadPoolSettingsPython310 (TestThreadPoolSettingsPython39 ):
575
+ class TestThreadPoolSettingsPython310 (TestThreadPoolSettingsPython37 ):
574
576
def setUp (self , version = SysVersionInfo (3 , 10 , 0 , 'final' , 0 )):
575
577
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
576
585
577
586
def tearDown (self ):
587
+ self .mock_os_cpu .stop ()
578
588
super (TestThreadPoolSettingsPython310 , self ).tearDown ()
579
589
580
590
@@ -583,12 +593,41 @@ def tearDown(self):
583
593
"as the default passed is None, the cpu_count determines the "
584
594
"number of max_workers and we cannot mock the os.cpu_count() "
585
595
"in the concurrent.futures.ThreadPoolExecutor" )
586
- class TestThreadPoolSettingsPython311 (TestThreadPoolSettingsPython310 ):
596
+ class TestThreadPoolSettingsPython311 (TestThreadPoolSettingsPython37 ):
587
597
def setUp (self , version = SysVersionInfo (3 , 11 , 0 , 'final' , 0 )):
588
598
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
589
606
590
607
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 ()
592
631
593
632
594
633
class TestDispatcherStein (testutils .AsyncTestCase ):
0 commit comments