3
3
import os
4
4
import sys
5
5
from 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
10
7
11
8
from azure_functions_worker .constants import (
12
9
PYTHON_ENABLE_DEBUG_LOGGING ,
13
10
PYTHON_ENABLE_INIT_INDEXING ,
14
11
PYTHON_ENABLE_WORKER_EXTENSIONS ,
15
12
PYTHON_ISOLATE_WORKER_DEPENDENCIES ,
16
13
)
14
+ from requests import Request
15
+ from tests .utils .testutils_lc import LinuxConsumptionWebHostController
17
16
18
17
_DEFAULT_HOST_VERSION = "4"
19
18
20
19
21
20
class 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
- """
33
21
34
22
@classmethod
35
23
def setUpClass (cls ):
@@ -65,6 +53,8 @@ def test_http_no_auth(self):
65
53
resp = ctrl .send_request (req )
66
54
self .assertEqual (resp .status_code , 200 )
67
55
56
+ @skipIf (sys .version_info .minor != 11 ,
57
+ "Uploaded common libraries are only supported for Python 3.11" )
68
58
def test_common_libraries (self ):
69
59
"""A function app with the following requirements.txt:
70
60
@@ -95,66 +85,6 @@ def test_common_libraries(self):
95
85
self .assertIn ('pyodbc' , content )
96
86
self .assertIn ('requests' , content )
97
87
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
-
158
88
def test_debug_logging_disabled (self ):
159
89
"""An HttpTrigger function app with 'azure-functions' library
160
90
should return 200 and by default customer debug logging should be
@@ -230,8 +160,6 @@ def test_pinning_functions_to_older_version(self):
230
160
self .assertEqual (resp .status_code , 200 )
231
161
self .assertIn ("Func Version: 1.11.1" , resp .text )
232
162
233
- @skipIf (sys .version_info .minor != 10 ,
234
- "This is testing only for python310" )
235
163
def test_opencensus_with_extensions_enabled (self ):
236
164
"""A function app with extensions enabled containing the
237
165
following libraries:
@@ -251,8 +179,6 @@ def test_opencensus_with_extensions_enabled(self):
251
179
resp = ctrl .send_request (req )
252
180
self .assertEqual (resp .status_code , 200 )
253
181
254
- @skipIf (sys .version_info .minor != 10 ,
255
- "This is testing only for python310" )
256
182
def test_opencensus_with_extensions_enabled_init_indexing (self ):
257
183
"""
258
184
A function app with init indexing enabled
@@ -269,43 +195,6 @@ def test_opencensus_with_extensions_enabled_init_indexing(self):
269
195
resp = ctrl .send_request (req )
270
196
self .assertEqual (resp .status_code , 200 )
271
197
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" )
309
198
def test_reload_variables_after_oom_error (self ):
310
199
"""
311
200
A function app with HTTPtrigger mocking error code 137
@@ -337,8 +226,7 @@ def test_reload_variables_after_oom_error(self):
337
226
self .assertNotIn ("Failure Exception: ModuleNotFoundError" ,
338
227
logs )
339
228
340
- @skipIf (sys .version_info .minor != 10 ,
341
- "This is testing only for python310" )
229
+ @skip ("Flaky test." )
342
230
def test_http_v2_fastapi_streaming_upload_download (self ):
343
231
"""
344
232
A function app using http v2 fastapi extension with streaming upload and
@@ -377,7 +265,10 @@ def generate_random_bytes_stream():
377
265
streamed_data , b'streamingtestingresponseisreturned' )
378
266
379
267
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