33import os
44import sys
55from time import sleep
6- from unittest import TestCase , skipIf
7-
8- from requests import Request
9- from tests .utils .testutils_lc import LinuxConsumptionWebHostController
6+ from unittest import TestCase , skip , skipIf
107
118from azure_functions_worker .constants import (
129 PYTHON_ENABLE_DEBUG_LOGGING ,
1310 PYTHON_ENABLE_INIT_INDEXING ,
1411 PYTHON_ENABLE_WORKER_EXTENSIONS ,
1512 PYTHON_ISOLATE_WORKER_DEPENDENCIES ,
1613)
14+ from requests import Request
15+ from tests .utils .testutils_lc import LinuxConsumptionWebHostController
1716
1817_DEFAULT_HOST_VERSION = "4"
1918
2019
2120class TestLinuxConsumption (TestCase ):
22- """Test worker behaviors on specific scenarios.
23-
24- SCM_RUN_FROM_PACKAGE: built function apps are acquired from
25- -> "Simple Batch" Subscription
26- -> "AzureFunctionsPythonWorkerCILinuxDevOps" Resource Group
27- -> "pythonworker<python_major><python_minor>sa" Storage Account
28- -> "python-worker-lc-apps" Blob Container
29-
30- For a list of scenario names:
31- https://pythonworker39sa.blob.core.windows.net/python-worker-lc-apps?restype=container&comp=list
32- """
3321
3422 @classmethod
3523 def setUpClass (cls ):
@@ -65,6 +53,8 @@ def test_http_no_auth(self):
6553 resp = ctrl .send_request (req )
6654 self .assertEqual (resp .status_code , 200 )
6755
56+ @skipIf (sys .version_info .minor != 11 ,
57+ "Uploaded common libraries are only supported for Python 3.11" )
6858 def test_common_libraries (self ):
6959 """A function app with the following requirements.txt:
7060
@@ -95,66 +85,6 @@ def test_common_libraries(self):
9585 self .assertIn ('pyodbc' , content )
9686 self .assertIn ('requests' , content )
9787
98- @skipIf (sys .version_info .minor in (10 , 11 ),
99- "Protobuf pinning fails during remote build" )
100- def test_new_protobuf (self ):
101- """A function app with the following requirements.txt:
102-
103- azure-functions==1.7.0
104- protobuf==3.15.8
105- grpcio==1.33.2
106-
107- should return 200 after importing all libraries.
108- """
109- with LinuxConsumptionWebHostController (_DEFAULT_HOST_VERSION ,
110- self ._py_version ) as ctrl :
111- ctrl .assign_container (env = {
112- "AzureWebJobsStorage" : self ._storage ,
113- "SCM_RUN_FROM_PACKAGE" : self ._get_blob_url ("NewProtobuf" ),
114- PYTHON_ISOLATE_WORKER_DEPENDENCIES : "1"
115- })
116- req = Request ('GET' , f'{ ctrl .url } /api/HttpTrigger' )
117- resp = ctrl .send_request (req )
118- self .assertEqual (resp .status_code , 200 )
119-
120- content = resp .json ()
121-
122- # Worker always picks up the SDK version bundled with the image
123- # Version of the packages are inconsistent due to isolation's bug
124- self .assertEqual (content ['azure.functions' ], '1.7.0' )
125- self .assertEqual (content ['google.protobuf' ], '3.15.8' )
126- self .assertEqual (content ['grpc' ], '1.33.2' )
127-
128- @skipIf (sys .version_info .minor in (10 , 11 ),
129- "Protobuf pinning fails during remote build" )
130- def test_old_protobuf (self ):
131- """A function app with the following requirements.txt:
132-
133- azure-functions==1.5.0
134- protobuf==3.8.0
135- grpcio==1.27.1
136-
137- should return 200 after importing all libraries.
138- """
139- with LinuxConsumptionWebHostController (_DEFAULT_HOST_VERSION ,
140- self ._py_version ) as ctrl :
141- ctrl .assign_container (env = {
142- "AzureWebJobsStorage" : self ._storage ,
143- "SCM_RUN_FROM_PACKAGE" : self ._get_blob_url ("OldProtobuf" ),
144- PYTHON_ISOLATE_WORKER_DEPENDENCIES : "1"
145- })
146- req = Request ('GET' , f'{ ctrl .url } /api/HttpTrigger' )
147- resp = ctrl .send_request (req )
148- self .assertEqual (resp .status_code , 200 )
149-
150- content = resp .json ()
151-
152- # Worker always picks up the SDK version bundled with the image
153- # Version of the packages are inconsistent due to isolation's bug
154- self .assertIn (content ['azure.functions' ], '1.5.0' )
155- self .assertIn (content ['google.protobuf' ], '3.8.0' )
156- self .assertIn (content ['grpc' ], '1.27.1' )
157-
15888 def test_debug_logging_disabled (self ):
15989 """An HttpTrigger function app with 'azure-functions' library
16090 should return 200 and by default customer debug logging should be
@@ -230,8 +160,6 @@ def test_pinning_functions_to_older_version(self):
230160 self .assertEqual (resp .status_code , 200 )
231161 self .assertIn ("Func Version: 1.11.1" , resp .text )
232162
233- @skipIf (sys .version_info .minor != 10 ,
234- "This is testing only for python310" )
235163 def test_opencensus_with_extensions_enabled (self ):
236164 """A function app with extensions enabled containing the
237165 following libraries:
@@ -251,8 +179,6 @@ def test_opencensus_with_extensions_enabled(self):
251179 resp = ctrl .send_request (req )
252180 self .assertEqual (resp .status_code , 200 )
253181
254- @skipIf (sys .version_info .minor != 10 ,
255- "This is testing only for python310" )
256182 def test_opencensus_with_extensions_enabled_init_indexing (self ):
257183 """
258184 A function app with init indexing enabled
@@ -269,43 +195,6 @@ def test_opencensus_with_extensions_enabled_init_indexing(self):
269195 resp = ctrl .send_request (req )
270196 self .assertEqual (resp .status_code , 200 )
271197
272- @skipIf (sys .version_info .minor != 9 ,
273- "This is testing only for python39 where extensions"
274- "enabled by default" )
275- def test_reload_variables_after_timeout_error (self ):
276- """
277- A function app with HTTPtrigger which has a function timeout of
278- 20s. The app as a sleep of 30s which should trigger a timeout
279- """
280- with LinuxConsumptionWebHostController (_DEFAULT_HOST_VERSION ,
281- self ._py_version ) as ctrl :
282- ctrl .assign_container (env = {
283- "AzureWebJobsStorage" : self ._storage ,
284- "SCM_RUN_FROM_PACKAGE" : self ._get_blob_url (
285- "TimeoutError" ),
286- PYTHON_ISOLATE_WORKER_DEPENDENCIES : "1"
287- })
288- req = Request ('GET' , f'{ ctrl .url } /api/hello' )
289- resp = ctrl .send_request (req )
290- self .assertEqual (resp .status_code , 500 )
291-
292- sleep (2 )
293- logs = ctrl .get_container_logs ()
294- self .assertRegex (
295- logs ,
296- r"Applying prioritize_customer_dependencies: "
297- r"worker_dependencies_path: \/azure-functions-host\/"
298- r"workers\/python\/.*?\/LINUX\/X64,"
299- r" customer_dependencies_path: \/home\/site\/wwwroot\/"
300- r"\.python_packages\/lib\/site-packages, working_directory:"
301- r" \/home\/site\/wwwroot, Linux Consumption: True,"
302- r" Placeholder: False" )
303- self .assertNotIn ("Failure Exception: ModuleNotFoundError" ,
304- logs )
305-
306- @skipIf (sys .version_info .minor != 9 ,
307- "This is testing only for python39 where extensions"
308- "enabled by default" )
309198 def test_reload_variables_after_oom_error (self ):
310199 """
311200 A function app with HTTPtrigger mocking error code 137
@@ -337,8 +226,7 @@ def test_reload_variables_after_oom_error(self):
337226 self .assertNotIn ("Failure Exception: ModuleNotFoundError" ,
338227 logs )
339228
340- @skipIf (sys .version_info .minor != 10 ,
341- "This is testing only for python310" )
229+ @skip ("Flaky test." )
342230 def test_http_v2_fastapi_streaming_upload_download (self ):
343231 """
344232 A function app using http v2 fastapi extension with streaming upload and
@@ -377,7 +265,10 @@ def generate_random_bytes_stream():
377265 streamed_data , b'streamingtestingresponseisreturned' )
378266
379267 def _get_blob_url (self , scenario_name : str ) -> str :
380- return (
381- f'https://pythonworker{ self ._py_shortform } sa.blob.core.windows.net/'
382- f'python-worker-lc-apps/{ scenario_name } { self ._py_shortform } .zip'
383- )
268+ base_url = "http://172.17.0.1:10000/devstoreaccount1/apps"
269+
270+ container_sas_token = os .getenv ('CONTAINER_SAS_TOKEN' )
271+ if not container_sas_token :
272+ raise RuntimeError ('Environment variable CONTAINER_SAS_TOKEN is '
273+ 'required before running Linux Consumption test' )
274+ return f"{ base_url } /{ scenario_name } .zip?{ container_sas_token } "
0 commit comments