|
20 | 20 | PYTHON_THREADPOOL_THREAD_COUNT,
|
21 | 21 | PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT,
|
22 | 22 | PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
|
23 |
| - PYTHON_THREADPOOL_THREAD_COUNT_MIN, |
| 23 | + PYTHON_THREADPOOL_THREAD_COUNT_MIN, HTTP_URI, REQUIRES_ROUTE_PARAMETERS, |
24 | 24 | )
|
25 | 25 | from azure_functions_worker.dispatcher import Dispatcher, ContextEnabledTask
|
26 | 26 | from azure_functions_worker.utils import config_manager
|
|
34 | 34 | 'dispatcher_functions_stein'
|
35 | 35 | FUNCTION_APP_DIRECTORY = UNIT_TESTS_ROOT / 'dispatcher_functions' / \
|
36 | 36 | 'dispatcher_functions_stein'
|
| 37 | +HTTPV2_FUNCTION_APP_DIRECTORY = UNIT_TESTS_ROOT / 'dispatcher_functions' / \ |
| 38 | + 'http_v2' / 'fastapi' |
37 | 39 |
|
38 | 40 |
|
39 | 41 | class TestThreadPoolSettingsPython37(testutils.AsyncTestCase):
|
@@ -778,6 +780,7 @@ def setUp(self):
|
778 | 780 | asyncio.set_event_loop(self.loop)
|
779 | 781 | self.dispatcher = testutils.create_dummy_dispatcher()
|
780 | 782 | sys.path.append(str(FUNCTION_APP_DIRECTORY))
|
| 783 | + sys.path.append(str(HTTPV2_FUNCTION_APP_DIRECTORY)) |
781 | 784 |
|
782 | 785 | def tearDown(self):
|
783 | 786 | self.loop.close()
|
@@ -1002,6 +1005,63 @@ def test_dispatcher_indexing_in_load_request_with_exception(
|
1002 | 1005 | response.function_load_response.result.exception.message,
|
1003 | 1006 | "Exception: Mocked Exception")
|
1004 | 1007 |
|
| 1008 | + @patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'true'}) |
| 1009 | + @patch("azure_functions_worker.http_v2.HttpV2Registry.http_v2_enabled", |
| 1010 | + return_value=True) |
| 1011 | + def test_dispatcher_http_v2_init_request_fail(self, mock_http_v2_enabled): |
| 1012 | + request = protos.StreamingMessage( |
| 1013 | + worker_init_request=protos.WorkerInitRequest( |
| 1014 | + host_version="2.3.4", |
| 1015 | + function_app_directory=str(HTTPV2_FUNCTION_APP_DIRECTORY) |
| 1016 | + ) |
| 1017 | + ) |
| 1018 | + |
| 1019 | + resp = self.loop.run_until_complete( |
| 1020 | + self.dispatcher._handle__worker_init_request(request) |
| 1021 | + ) |
| 1022 | + |
| 1023 | + mock_http_v2_enabled.assert_called_once() |
| 1024 | + self.assertIsNotNone(self.dispatcher._function_metadata_exception) |
| 1025 | + |
| 1026 | + capabilities = resp.worker_init_response.capabilities |
| 1027 | + self.assertNotIn(HTTP_URI, capabilities) |
| 1028 | + self.assertNotIn(REQUIRES_ROUTE_PARAMETERS, capabilities) |
| 1029 | + |
| 1030 | + # Cleanup |
| 1031 | + del sys.modules['function_app'] |
| 1032 | + |
| 1033 | + @patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'true'}) |
| 1034 | + @patch("azure_functions_worker.http_v2.HttpV2Registry.http_v2_enabled", |
| 1035 | + return_value=True) |
| 1036 | + @patch("azure_functions_worker.dispatcher.initialize_http_server", |
| 1037 | + return_value="http://localhost:8080") |
| 1038 | + @patch("azure_functions_worker.dispatcher.Dispatcher" |
| 1039 | + ".load_function_metadata") |
| 1040 | + def test_dispatcher_http_v2_init_request_pass(self, mock_http_v2_enabled, |
| 1041 | + mock_init_http_server, |
| 1042 | + mock_load_func_metadata): |
| 1043 | + request = protos.StreamingMessage( |
| 1044 | + worker_init_request=protos.WorkerInitRequest( |
| 1045 | + host_version="2.3.4", |
| 1046 | + function_app_directory=str(HTTPV2_FUNCTION_APP_DIRECTORY) |
| 1047 | + ) |
| 1048 | + ) |
| 1049 | + |
| 1050 | + resp = self.loop.run_until_complete( |
| 1051 | + self.dispatcher._handle__worker_init_request(request) |
| 1052 | + ) |
| 1053 | + |
| 1054 | + mock_http_v2_enabled.assert_called_once() |
| 1055 | + mock_init_http_server.assert_called_once() |
| 1056 | + mock_load_func_metadata.assert_called_once() |
| 1057 | + self.assertIsNone(self.dispatcher._function_metadata_exception) |
| 1058 | + |
| 1059 | + capabilities = resp.worker_init_response.capabilities |
| 1060 | + self.assertIn(HTTP_URI, capabilities) |
| 1061 | + self.assertEqual(capabilities[HTTP_URI], "http://localhost:8080") |
| 1062 | + self.assertIn(REQUIRES_ROUTE_PARAMETERS, capabilities) |
| 1063 | + self.assertEqual(capabilities[REQUIRES_ROUTE_PARAMETERS], "true") |
| 1064 | + |
1005 | 1065 |
|
1006 | 1066 | class TestContextEnabledTask(unittest.TestCase):
|
1007 | 1067 | def setUp(self):
|
|
0 commit comments