|
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.version import VERSION
|
|
33 | 33 | 'dispatcher_functions_stein'
|
34 | 34 | FUNCTION_APP_DIRECTORY = UNIT_TESTS_ROOT / 'dispatcher_functions' / \
|
35 | 35 | 'dispatcher_functions_stein'
|
| 36 | +HTTPV2_FUNCTION_APP_DIRECTORY = UNIT_TESTS_ROOT / 'dispatcher_functions' / \ |
| 37 | + 'http_v2' / 'fastapi' |
36 | 38 |
|
37 | 39 |
|
38 | 40 | class TestThreadPoolSettingsPython37(testutils.AsyncTestCase):
|
@@ -767,6 +769,7 @@ def setUp(self):
|
767 | 769 | asyncio.set_event_loop(self.loop)
|
768 | 770 | self.dispatcher = testutils.create_dummy_dispatcher()
|
769 | 771 | sys.path.append(str(FUNCTION_APP_DIRECTORY))
|
| 772 | + sys.path.append(str(HTTPV2_FUNCTION_APP_DIRECTORY)) |
770 | 773 |
|
771 | 774 | def tearDown(self):
|
772 | 775 | self.loop.close()
|
@@ -991,6 +994,63 @@ def test_dispatcher_indexing_in_load_request_with_exception(
|
991 | 994 | response.function_load_response.result.exception.message,
|
992 | 995 | "Exception: Mocked Exception")
|
993 | 996 |
|
| 997 | + @patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'true'}) |
| 998 | + @patch("azure_functions_worker.http_v2.HttpV2Registry.http_v2_enabled", |
| 999 | + return_value=True) |
| 1000 | + def test_dispatcher_http_v2_init_request_fail(self, mock_http_v2_enabled): |
| 1001 | + request = protos.StreamingMessage( |
| 1002 | + worker_init_request=protos.WorkerInitRequest( |
| 1003 | + host_version="2.3.4", |
| 1004 | + function_app_directory=str(HTTPV2_FUNCTION_APP_DIRECTORY) |
| 1005 | + ) |
| 1006 | + ) |
| 1007 | + |
| 1008 | + resp = self.loop.run_until_complete( |
| 1009 | + self.dispatcher._handle__worker_init_request(request) |
| 1010 | + ) |
| 1011 | + |
| 1012 | + mock_http_v2_enabled.assert_called_once() |
| 1013 | + self.assertIsNotNone(self.dispatcher._function_metadata_exception) |
| 1014 | + |
| 1015 | + capabilities = resp.worker_init_response.capabilities |
| 1016 | + self.assertNotIn(HTTP_URI, capabilities) |
| 1017 | + self.assertNotIn(REQUIRES_ROUTE_PARAMETERS, capabilities) |
| 1018 | + |
| 1019 | + # Cleanup |
| 1020 | + del sys.modules['function_app'] |
| 1021 | + |
| 1022 | + @patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'true'}) |
| 1023 | + @patch("azure_functions_worker.http_v2.HttpV2Registry.http_v2_enabled", |
| 1024 | + return_value=True) |
| 1025 | + @patch("azure_functions_worker.dispatcher.initialize_http_server", |
| 1026 | + return_value="http://localhost:8080") |
| 1027 | + @patch("azure_functions_worker.dispatcher.Dispatcher" |
| 1028 | + ".load_function_metadata") |
| 1029 | + def test_dispatcher_http_v2_init_request_pass(self, mock_http_v2_enabled, |
| 1030 | + mock_init_http_server, |
| 1031 | + mock_load_func_metadata): |
| 1032 | + request = protos.StreamingMessage( |
| 1033 | + worker_init_request=protos.WorkerInitRequest( |
| 1034 | + host_version="2.3.4", |
| 1035 | + function_app_directory=str(HTTPV2_FUNCTION_APP_DIRECTORY) |
| 1036 | + ) |
| 1037 | + ) |
| 1038 | + |
| 1039 | + resp = self.loop.run_until_complete( |
| 1040 | + self.dispatcher._handle__worker_init_request(request) |
| 1041 | + ) |
| 1042 | + |
| 1043 | + mock_http_v2_enabled.assert_called_once() |
| 1044 | + mock_init_http_server.assert_called_once() |
| 1045 | + mock_load_func_metadata.assert_called_once() |
| 1046 | + self.assertIsNone(self.dispatcher._function_metadata_exception) |
| 1047 | + |
| 1048 | + capabilities = resp.worker_init_response.capabilities |
| 1049 | + self.assertIn(HTTP_URI, capabilities) |
| 1050 | + self.assertEqual(capabilities[HTTP_URI], "http://localhost:8080") |
| 1051 | + self.assertIn(REQUIRES_ROUTE_PARAMETERS, capabilities) |
| 1052 | + self.assertEqual(capabilities[REQUIRES_ROUTE_PARAMETERS], "true") |
| 1053 | + |
994 | 1054 |
|
995 | 1055 | class TestContextEnabledTask(unittest.TestCase):
|
996 | 1056 | def setUp(self):
|
|
0 commit comments