1
1
# Copyright (c) Microsoft Corporation. All rights reserved.
2
2
# Licensed under the MIT License.
3
-
3
+ import threading
4
4
import unittest
5
5
from io import StringIO , BytesIO
6
6
@@ -113,7 +113,8 @@ def test_request_parse_function_context(self):
113
113
environ = WsgiRequest (func_request ,
114
114
func_context ).to_environ (error_buffer )
115
115
self .assertEqual (environ ['azure_functions.invocation_id' ],
116
- '123e4567-e89b-12d3-a456-426655440000' )
116
+ '123e4567-e89b-12d3-a456-426655440000' ),
117
+ self .assertIsNotNone (environ ['azure_functions.thread_local_storage' ])
117
118
self .assertEqual (environ ['azure_functions.function_name' ],
118
119
'httptrigger' )
119
120
self .assertEqual (environ ['azure_functions.function_directory' ],
@@ -236,14 +237,16 @@ def _generate_func_request(
236
237
def _generate_func_context (
237
238
self ,
238
239
invocation_id = '123e4567-e89b-12d3-a456-426655440000' ,
240
+ thread_local_storage = threading .local (),
239
241
function_name = 'httptrigger' ,
240
242
function_directory = '/home/roger/wwwroot/httptrigger' ,
241
243
trace_context = TraceContext ,
242
244
retry_context = RetryContext
243
245
) -> func .Context :
244
246
class MockContext (func .Context ):
245
- def __init__ (self , ii , fn , fd , tc , rc ):
247
+ def __init__ (self , ii , tls , fn , fd , tc , rc ):
246
248
self ._invocation_id = ii
249
+ self ._thread_local_storage = tls
247
250
self ._function_name = fn
248
251
self ._function_directory = fd
249
252
self ._trace_context = tc
@@ -253,6 +256,10 @@ def __init__(self, ii, fn, fd, tc, rc):
253
256
def invocation_id (self ):
254
257
return self ._invocation_id
255
258
259
+ @property
260
+ def thread_local_storage (self ):
261
+ return self ._thread_local_storage
262
+
256
263
@property
257
264
def function_name (self ):
258
265
return self ._function_name
@@ -269,7 +276,8 @@ def trace_context(self):
269
276
def retry_context (self ):
270
277
return self ._retry_context
271
278
272
- return MockContext (invocation_id , function_name , function_directory ,
279
+ return MockContext (invocation_id , thread_local_storage ,
280
+ function_name , function_directory ,
273
281
trace_context , retry_context )
274
282
275
283
def _generate_wsgi_app (self ,
0 commit comments