From 265121bee847e9af3b4a77dbce90091f68e1435a Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Thu, 27 Oct 2022 13:42:59 -0500 Subject: [PATCH 1/9] add e2e test for PYTHON_THREADPOOL_THREAD_COUNT. --- .../http_functions/http_func/__init__.py | 13 ++ .../http_functions/http_func/function.json | 20 +++ .../http_functions_stein/function_app.py | 10 ++ ...test_threadpool_thread__count_functions.py | 127 ++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 tests/endtoend/http_functions/http_func/__init__.py create mode 100644 tests/endtoend/http_functions/http_func/function.json create mode 100644 tests/endtoend/test_threadpool_thread__count_functions.py diff --git a/tests/endtoend/http_functions/http_func/__init__.py b/tests/endtoend/http_functions/http_func/__init__.py new file mode 100644 index 000000000..6e8cb7118 --- /dev/null +++ b/tests/endtoend/http_functions/http_func/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +from datetime import datetime +# flake8: noqa +import azure.functions as func +import time + + +def main(req: func.HttpRequest) -> func.HttpResponse: + time.sleep(1) + + current_time = datetime.now().strftime("%H:%M:%S") + return func.HttpResponse(f"{current_time}") diff --git a/tests/endtoend/http_functions/http_func/function.json b/tests/endtoend/http_functions/http_func/function.json new file mode 100644 index 000000000..b8dc650e9 --- /dev/null +++ b/tests/endtoend/http_functions/http_func/function.json @@ -0,0 +1,20 @@ +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "function", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + } + ] +} diff --git a/tests/endtoend/http_functions/http_functions_stein/function_app.py b/tests/endtoend/http_functions/http_functions_stein/function_app.py index 873fce914..213f71719 100644 --- a/tests/endtoend/http_functions/http_functions_stein/function_app.py +++ b/tests/endtoend/http_functions/http_functions_stein/function_app.py @@ -1,7 +1,9 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +from datetime import datetime import logging +import time import azure.functions as func @@ -32,3 +34,11 @@ def default_template(req: func.HttpRequest) -> func.HttpResponse: " personalized response.", status_code=200 ) + + +@app.route(route="http_func") +def http_func(req: func.HttpRequest) -> func.HttpResponse: + time.sleep(2) + + current_time = datetime.now().strftime("%H:%M:%S") + return func.HttpResponse(f"{current_time}") diff --git a/tests/endtoend/test_threadpool_thread__count_functions.py b/tests/endtoend/test_threadpool_thread__count_functions.py new file mode 100644 index 000000000..828b3da28 --- /dev/null +++ b/tests/endtoend/test_threadpool_thread__count_functions.py @@ -0,0 +1,127 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +import os +from threading import Thread +from unittest.mock import patch +from datetime import datetime +from tests.utils import testutils + + +class TestPythonThreadpoolThreadCount1(testutils.WebHostTestCase): + """Test the native Http Trigger in the local webhost. + This test class will spawn a webhost from your /build/webhost + folder and replace the built-in Python with azure_functions_worker from + your code base. this file is more focus on testing the E2E flow scenarios. + """ + + def setUp(self): + self._patch_environ = patch.dict('os.environ', os.environ.copy()) + self._patch_environ.start() + super().setUp() + + @classmethod + def setUpClass(cls): + os_environ = os.environ.copy() + os_environ['PYTHON_THREADPOOL_THREAD_COUNT'] = '1' + cls._patch_environ = patch.dict('os.environ', os_environ) + cls._patch_environ.start() + super().setUpClass() + + def tearDown(self): + super().tearDown() + self._patch_environ.stop() + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' + + @testutils.retryable_test(3, 5) + def test_http_func_with_thread_count_1(self): + res = [None, None] + + def http_req(response_num): + r = self.webhost.request('GET', 'http_func') + self.assertTrue(r.ok) + res[response_num] = datetime.strptime( + r.content.decode("utf-8"), "%H:%M:%S") + + # creating 2 different threads to send parallel HTTP request + trd1 = Thread(target=http_req, args=(0,)) + trd2 = Thread(target=http_req, args=(1,)) + trd1.start() + trd2.start() + trd1.join() + trd2.join() + """time returned from both of the HTTP request should be greater than + of equal to 2 since both the request should not be processed at the + same time because PYTHON_THREADPOOL_THREAD_COUNT is 1""" + time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) + self.assertTrue(time_diff_in_seconds >= 1) + + +class TestPythonThreadpoolThreadCount1Stein(TestPythonThreadpoolThreadCount1): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ + 'http_functions_stein' + + +class TestPythonThreadpoolThreadCount2(testutils.WebHostTestCase): + """Test the native Http Trigger in the local webhost. + This test class will spawn a webhost from your /build/webhost + folder and replace the built-in Python with azure_functions_worker from + your code base. this file is more focus on testing the E2E flow scenarios. + """ + + def setUp(self): + self._patch_environ = patch.dict('os.environ', os.environ.copy()) + self._patch_environ.start() + super().setUp() + + @classmethod + def setUpClass(cls): + os_environ = os.environ.copy() + os_environ['PYTHON_THREADPOOL_THREAD_COUNT'] = '2' + cls._patch_environ = patch.dict('os.environ', os_environ) + cls._patch_environ.start() + super().setUpClass() + + def tearDown(self): + super().tearDown() + self._patch_environ.stop() + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' + + @testutils.retryable_test(3, 5) + def test_http_func_with_thread_count_2(self): + response = [None, None] + + def http_req(res_num): + r = self.webhost.request('GET', 'http_func') + self.assertTrue(r.ok) + response[res_num] = datetime.strptime( + r.content.decode("utf-8"), "%H:%M:%S") + + # creating 2 different threads to send HTTP request + thread1 = Thread(target=http_req, args=(0,)) + thread2 = Thread(target=http_req, args=(1,)) + thread1.start() + thread2.start() + thread1.join() + thread2.join() + """time returned from both of the HTTP request should be less than + 2 since both the request should be processed at the + same time because PYTHON_THREADPOOL_THREAD_COUNT is 2""" + time_diff_in_seconds = abs((response[0] - response[1]).total_seconds()) + self.assertTrue(time_diff_in_seconds < 1) + + +class TestPythonThreadpoolThreadCount2Stein(TestPythonThreadpoolThreadCount2): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ + 'http_functions_stein' From 62cc9f32e98ba5d3b504ca5b881780c1a272b8fc Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Thu, 27 Oct 2022 13:54:42 -0500 Subject: [PATCH 2/9] update --- .../http_functions/http_functions_stein/function_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/endtoend/http_functions/http_functions_stein/function_app.py b/tests/endtoend/http_functions/http_functions_stein/function_app.py index 213f71719..01fd52a09 100644 --- a/tests/endtoend/http_functions/http_functions_stein/function_app.py +++ b/tests/endtoend/http_functions/http_functions_stein/function_app.py @@ -38,7 +38,7 @@ def default_template(req: func.HttpRequest) -> func.HttpResponse: @app.route(route="http_func") def http_func(req: func.HttpRequest) -> func.HttpResponse: - time.sleep(2) + time.sleep(1) current_time = datetime.now().strftime("%H:%M:%S") return func.HttpResponse(f"{current_time}") From a9fad4a5cc53b0f8f4859555dba0a49e8bfc4518 Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Mon, 31 Oct 2022 12:37:25 -0500 Subject: [PATCH 3/9] add e2e test for FUNCTIONS_WORKER_PROCESS_COUNT. --- .../test_worker_proccess_count_functions.py | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 tests/endtoend/test_worker_proccess_count_functions.py diff --git a/tests/endtoend/test_worker_proccess_count_functions.py b/tests/endtoend/test_worker_proccess_count_functions.py new file mode 100644 index 000000000..60a2ff658 --- /dev/null +++ b/tests/endtoend/test_worker_proccess_count_functions.py @@ -0,0 +1,133 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +import os +from threading import Thread +from unittest.mock import patch +from datetime import datetime +from tests.utils import testutils +from unittest import skip + + +class TestWorkerProcessCount1(testutils.WebHostTestCase): + """Test the Http Trigger with setting up the python worker process count + to 2. This test class will spawn a webhost from your + /build/webhost folder and replace the built-in Python with + azure_functions_worker from your code base. this file is more focused + on testing the E2E flow scenario for FUNCTIONS_WORKER_PROCESS_COUNT feature. + """ + + def setUp(self): + self._patch_environ = patch.dict('os.environ', os.environ.copy()) + self._patch_environ.start() + super().setUp() + + @classmethod + def setUpClass(cls): + os_environ = os.environ.copy() + os_environ['PYTHON_THREADPOOL_THREAD_COUNT'] = '1' + os_environ['FUNCTIONS_WORKER_PROCESS_COUNT'] = '1' + cls._patch_environ = patch.dict('os.environ', os_environ) + cls._patch_environ.start() + super().setUpClass() + + def tearDown(self): + super().tearDown() + self._patch_environ.stop() + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' + + @testutils.retryable_test(3, 5) + def test_http_func_with_worker_process_count_1(self): + res = [None, None] + + def http_req(response_num): + r = self.webhost.request('GET', 'http_func') + self.assertTrue(r.ok) + res[response_num] = datetime.strptime( + r.content.decode("utf-8"), "%H:%M:%S") + + # creating 2 different threads to send HTTP request + trd1 = Thread(target=http_req, args=(0,)) + trd2 = Thread(target=http_req, args=(1,)) + trd1.start() + trd2.start() + trd1.join() + trd2.join() + '''time returned from both of the HTTP request should be greater than + of equal to 1 since both the request should not be processed at the + same time because FUNCTIONS_WORKER_PROCESS_COUNT is 1''' + time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) + self.assertTrue(time_diff_in_seconds >= 1) + + +class TestWorkerProcessCount1Stein(TestWorkerProcessCount1): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ + 'http_functions_stein' + + +class TestWorkerProcessCount2(testutils.WebHostTestCase): + """Test the Http Trigger with setting up the python worker process count + to 2. This test class will spawn a webhost from your + /build/webhost folder and replace the built-in Python with + azure_functions_worker from your code base. this file is more focused + on testing the E2E flow scenario for FUNCTIONS_WORKER_PROCESS_COUNT feature. + """ + + def setUp(self): + self._patch_environ = patch.dict('os.environ', os.environ.copy()) + self._patch_environ.start() + super().setUp() + + @classmethod + def setUpClass(cls): + os_environ = os.environ.copy() + os_environ['PYTHON_THREADPOOL_THREAD_COUNT'] = '1' + os_environ['FUNCTIONS_WORKER_PROCESS_COUNT'] = '2' + cls._patch_environ = patch.dict('os.environ', os_environ) + cls._patch_environ.start() + super().setUpClass() + + def tearDown(self): + super().tearDown() + self._patch_environ.stop() + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' + + @testutils.retryable_test(3, 5) + def test_http_func_with_worker_process_count_2(self): + response = [None, None] + + def http_req(res_num): + r = self.webhost.request('GET', 'http_func') + self.assertTrue(r.ok) + response[res_num] = datetime.strptime( + r.content.decode("utf-8"), "%H:%M:%S") + + # creating 2 different threads to send HTTP request + thread1 = Thread(target=http_req, args=(0,)) + thread2 = Thread(target=http_req, args=(1,)) + thread1.start() + thread2.start() + thread1.join() + thread2.join() + '''time returned from both of the HTTP request should be less than + 1 since both the request should be processed at the + same time because FUNCTIONS_WORKER_PROCESS_COUNT is 2''' + time_diff_in_seconds = abs((response[0] - response[1]).total_seconds()) + self.assertTrue(time_diff_in_seconds < 2) + + +@skip("skipping test for pystein worker process count 2") +class TestWorkerProcessCount2Stein(TestWorkerProcessCount2): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ + 'http_functions_stein' From 8b44658c8d1d6e151c2cfbd939739093aba8610a Mon Sep 17 00:00:00 2001 From: pthummar Date: Fri, 11 Nov 2022 16:22:04 -0600 Subject: [PATCH 4/9] updated typo. --- tests/endtoend/test_worker_proccess_count_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/endtoend/test_worker_proccess_count_functions.py b/tests/endtoend/test_worker_proccess_count_functions.py index 60a2ff658..06ae72982 100644 --- a/tests/endtoend/test_worker_proccess_count_functions.py +++ b/tests/endtoend/test_worker_proccess_count_functions.py @@ -118,7 +118,7 @@ def http_req(res_num): thread1.join() thread2.join() '''time returned from both of the HTTP request should be less than - 1 since both the request should be processed at the + 2 since both the request should be processed at the same time because FUNCTIONS_WORKER_PROCESS_COUNT is 2''' time_diff_in_seconds = abs((response[0] - response[1]).total_seconds()) self.assertTrue(time_diff_in_seconds < 2) From 61dffd6c1a8131ae65bccb1cf8726e49bff19e18 Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Tue, 14 Feb 2023 12:12:06 -0600 Subject: [PATCH 5/9] updated files. --- tests/endtoend/test_multi_worker_functions.py | 43 ------------------ ...test_threadpool_thread__count_functions.py | 45 ++++++++----------- .../test_worker_proccess_count_functions.py | 43 +++++++----------- 3 files changed, 35 insertions(+), 96 deletions(-) delete mode 100644 tests/endtoend/test_multi_worker_functions.py diff --git a/tests/endtoend/test_multi_worker_functions.py b/tests/endtoend/test_multi_worker_functions.py deleted file mode 100644 index 828030c88..000000000 --- a/tests/endtoend/test_multi_worker_functions.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. -import os -from threading import Thread -from unittest.mock import patch - -from tests.utils import testutils - - -class TestWorkerProcessCountStein(testutils.WebHostTestCase): - """Test the Http Trigger with setting up the python worker process count to 2. - This tests will check if worker1 indexes the function in metadata request - and worker2 indexes the function in the load request since worker2 does not - call metadata request. - """ - @classmethod - def setUpClass(cls): - os_environ = os.environ.copy() - os_environ['FUNCTIONS_WORKER_PROCESS_COUNT'] = '2' - cls._patch_environ = patch.dict('os.environ', os_environ) - cls._patch_environ.start() - super().setUpClass() - - @classmethod - def get_script_dir(cls): - return testutils.E2E_TESTS_FOLDER / 'http_functions' / \ - 'http_functions_stein' - - def test_http_func_with_worker_process_count(self): - """Test if the default template of Http trigger in Python Function app - will return OK - """ - def http_req(): - r = self.webhost.request('GET', 'default_template') - self.assertTrue(r.ok) - - # creating 2 different threads to send HTTP request - trd1 = Thread(target=http_req, args=(0,)) - trd2 = Thread(target=http_req, args=(1,)) - trd1.start() - trd2.start() - trd1.join() - trd2.join() diff --git a/tests/endtoend/test_threadpool_thread__count_functions.py b/tests/endtoend/test_threadpool_thread__count_functions.py index 828b3da28..256ffea93 100644 --- a/tests/endtoend/test_threadpool_thread__count_functions.py +++ b/tests/endtoend/test_threadpool_thread__count_functions.py @@ -8,17 +8,12 @@ class TestPythonThreadpoolThreadCount1(testutils.WebHostTestCase): - """Test the native Http Trigger in the local webhost. - This test class will spawn a webhost from your /build/webhost - folder and replace the built-in Python with azure_functions_worker from - your code base. this file is more focus on testing the E2E flow scenarios. + """ Test the Http Trigger with setting up the python threadpool thread + count to 1.this test will check if both requests should not be processed + at the same time. this file is more focus on testing the E2E flow + scenarios. """ - def setUp(self): - self._patch_environ = patch.dict('os.environ', os.environ.copy()) - self._patch_environ.start() - super().setUp() - @classmethod def setUpClass(cls): os_environ = os.environ.copy() @@ -52,9 +47,11 @@ def http_req(response_num): trd2.start() trd1.join() trd2.join() - """time returned from both of the HTTP request should be greater than - of equal to 2 since both the request should not be processed at the - same time because PYTHON_THREADPOOL_THREAD_COUNT is 1""" + """function execution time difference between both HTTP request + should be greater than of equal to 1 since both the request should + not be processed at the same time because + PYTHON_THREADPOOL_THREAD_COUNT is 1. + """ time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) self.assertTrue(time_diff_in_seconds >= 1) @@ -63,22 +60,17 @@ class TestPythonThreadpoolThreadCount1Stein(TestPythonThreadpoolThreadCount1): @classmethod def get_script_dir(cls): - return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ + return testutils.E2E_TESTS_FOLDER / 'http_functions' / \ 'http_functions_stein' class TestPythonThreadpoolThreadCount2(testutils.WebHostTestCase): - """Test the native Http Trigger in the local webhost. - This test class will spawn a webhost from your /build/webhost - folder and replace the built-in Python with azure_functions_worker from - your code base. this file is more focus on testing the E2E flow scenarios. + """ Test the Http Trigger with setting up the python threadpool thread + count to 2. this test will check if both requests should be processed + at the same time. this file is more focus on testing the E2E flow + scenarios. """ - def setUp(self): - self._patch_environ = patch.dict('os.environ', os.environ.copy()) - self._patch_environ.start() - super().setUp() - @classmethod def setUpClass(cls): os_environ = os.environ.copy() @@ -112,9 +104,10 @@ def http_req(res_num): thread2.start() thread1.join() thread2.join() - """time returned from both of the HTTP request should be less than - 2 since both the request should be processed at the - same time because PYTHON_THREADPOOL_THREAD_COUNT is 2""" + """function execution time difference between both HTTP request + should be less than 1 since both the request should be processed at + the same time because PYTHON_THREADPOOL_THREAD_COUNT is 2. + """ time_diff_in_seconds = abs((response[0] - response[1]).total_seconds()) self.assertTrue(time_diff_in_seconds < 1) @@ -123,5 +116,5 @@ class TestPythonThreadpoolThreadCount2Stein(TestPythonThreadpoolThreadCount2): @classmethod def get_script_dir(cls): - return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ + return testutils.E2E_TESTS_FOLDER / 'http_functions' / \ 'http_functions_stein' diff --git a/tests/endtoend/test_worker_proccess_count_functions.py b/tests/endtoend/test_worker_proccess_count_functions.py index 06ae72982..5ee0a1b23 100644 --- a/tests/endtoend/test_worker_proccess_count_functions.py +++ b/tests/endtoend/test_worker_proccess_count_functions.py @@ -5,22 +5,15 @@ from unittest.mock import patch from datetime import datetime from tests.utils import testutils -from unittest import skip class TestWorkerProcessCount1(testutils.WebHostTestCase): """Test the Http Trigger with setting up the python worker process count - to 2. This test class will spawn a webhost from your - /build/webhost folder and replace the built-in Python with - azure_functions_worker from your code base. this file is more focused - on testing the E2E flow scenario for FUNCTIONS_WORKER_PROCESS_COUNT feature. + to 2. this test will check if both requests should not be processed at + the same time. this file is more focused on testing the E2E flow scenario + for FUNCTIONS_WORKER_PROCESS_COUNT feature. """ - def setUp(self): - self._patch_environ = patch.dict('os.environ', os.environ.copy()) - self._patch_environ.start() - super().setUp() - @classmethod def setUpClass(cls): os_environ = os.environ.copy() @@ -55,9 +48,11 @@ def http_req(response_num): trd2.start() trd1.join() trd2.join() - '''time returned from both of the HTTP request should be greater than - of equal to 1 since both the request should not be processed at the - same time because FUNCTIONS_WORKER_PROCESS_COUNT is 1''' + """function execution time difference between both HTTP request + should be greater than of equal to 1 since both the request should + not be processed at the same time because + FUNCTIONS_WORKER_PROCESS_COUNT is 1. + """ time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) self.assertTrue(time_diff_in_seconds >= 1) @@ -72,17 +67,11 @@ def get_script_dir(cls): class TestWorkerProcessCount2(testutils.WebHostTestCase): """Test the Http Trigger with setting up the python worker process count - to 2. This test class will spawn a webhost from your - /build/webhost folder and replace the built-in Python with - azure_functions_worker from your code base. this file is more focused - on testing the E2E flow scenario for FUNCTIONS_WORKER_PROCESS_COUNT feature. + to 2. this test will check if both requests should be processed at the + same time. this file is more focused on testing the E2E flow scenario for + FUNCTIONS_WORKER_PROCESS_COUNT feature. """ - def setUp(self): - self._patch_environ = patch.dict('os.environ', os.environ.copy()) - self._patch_environ.start() - super().setUp() - @classmethod def setUpClass(cls): os_environ = os.environ.copy() @@ -117,14 +106,14 @@ def http_req(res_num): thread2.start() thread1.join() thread2.join() - '''time returned from both of the HTTP request should be less than - 2 since both the request should be processed at the - same time because FUNCTIONS_WORKER_PROCESS_COUNT is 2''' + '''function execution time difference between both HTTP request + should be less than 1 since both request should be processed at the + same time because FUNCTIONS_WORKER_PROCESS_COUNT is 2. + ''' time_diff_in_seconds = abs((response[0] - response[1]).total_seconds()) - self.assertTrue(time_diff_in_seconds < 2) + self.assertTrue(time_diff_in_seconds < 1) -@skip("skipping test for pystein worker process count 2") class TestWorkerProcessCount2Stein(TestWorkerProcessCount2): @classmethod From 468081d5bf59958d7047ca951694774e5dd56405 Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Tue, 14 Feb 2023 12:55:33 -0600 Subject: [PATCH 6/9] removed trailing white spaces. --- .../test_threadpool_thread__count_functions.py | 10 +++++----- tests/endtoend/test_worker_proccess_count_functions.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/endtoend/test_threadpool_thread__count_functions.py b/tests/endtoend/test_threadpool_thread__count_functions.py index 256ffea93..e5b23dab1 100644 --- a/tests/endtoend/test_threadpool_thread__count_functions.py +++ b/tests/endtoend/test_threadpool_thread__count_functions.py @@ -47,9 +47,9 @@ def http_req(response_num): trd2.start() trd1.join() trd2.join() - """function execution time difference between both HTTP request - should be greater than of equal to 1 since both the request should - not be processed at the same time because + """function execution time difference between both HTTP request + should be greater than of equal to 1 since both the request should + not be processed at the same time because PYTHON_THREADPOOL_THREAD_COUNT is 1. """ time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) @@ -104,8 +104,8 @@ def http_req(res_num): thread2.start() thread1.join() thread2.join() - """function execution time difference between both HTTP request - should be less than 1 since both the request should be processed at + """function execution time difference between both HTTP request + should be less than 1 since both the request should be processed at the same time because PYTHON_THREADPOOL_THREAD_COUNT is 2. """ time_diff_in_seconds = abs((response[0] - response[1]).total_seconds()) diff --git a/tests/endtoend/test_worker_proccess_count_functions.py b/tests/endtoend/test_worker_proccess_count_functions.py index 5ee0a1b23..4f8f69c87 100644 --- a/tests/endtoend/test_worker_proccess_count_functions.py +++ b/tests/endtoend/test_worker_proccess_count_functions.py @@ -48,9 +48,9 @@ def http_req(response_num): trd2.start() trd1.join() trd2.join() - """function execution time difference between both HTTP request - should be greater than of equal to 1 since both the request should - not be processed at the same time because + """function execution time difference between both HTTP request + should be greater than of equal to 1 since both the request should + not be processed at the same time because FUNCTIONS_WORKER_PROCESS_COUNT is 1. """ time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) @@ -106,8 +106,8 @@ def http_req(res_num): thread2.start() thread1.join() thread2.join() - '''function execution time difference between both HTTP request - should be less than 1 since both request should be processed at the + '''function execution time difference between both HTTP request + should be less than 1 since both request should be processed at the same time because FUNCTIONS_WORKER_PROCESS_COUNT is 2. ''' time_diff_in_seconds = abs((response[0] - response[1]).total_seconds()) From 12de8f3393e10f27f12656b35cc97747fded9937 Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:39:52 -0600 Subject: [PATCH 7/9] addressed comments --- tests/endtoend/test_worker_proccess_count_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/endtoend/test_worker_proccess_count_functions.py b/tests/endtoend/test_worker_proccess_count_functions.py index 4f8f69c87..e6da0564a 100644 --- a/tests/endtoend/test_worker_proccess_count_functions.py +++ b/tests/endtoend/test_worker_proccess_count_functions.py @@ -9,7 +9,7 @@ class TestWorkerProcessCount1(testutils.WebHostTestCase): """Test the Http Trigger with setting up the python worker process count - to 2. this test will check if both requests should not be processed at + to 1. this test will check if both requests should not be processed at the same time. this file is more focused on testing the E2E flow scenario for FUNCTIONS_WORKER_PROCESS_COUNT feature. """ From 9f593cea94faffec9146bbb08294dca8b36189da Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Fri, 17 Feb 2023 12:25:22 -0600 Subject: [PATCH 8/9] removed tests for worker and threadpool count 1. --- .../http_functions/http_func/function.json | 2 +- ...test_threadpool_thread__count_functions.py | 57 ------------------ .../test_worker_proccess_count_functions.py | 58 ------------------- 3 files changed, 1 insertion(+), 116 deletions(-) diff --git a/tests/endtoend/http_functions/http_func/function.json b/tests/endtoend/http_functions/http_func/function.json index b8dc650e9..8c4cbe307 100644 --- a/tests/endtoend/http_functions/http_func/function.json +++ b/tests/endtoend/http_functions/http_func/function.json @@ -2,7 +2,7 @@ "scriptFile": "__init__.py", "bindings": [ { - "authLevel": "function", + "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req", diff --git a/tests/endtoend/test_threadpool_thread__count_functions.py b/tests/endtoend/test_threadpool_thread__count_functions.py index e5b23dab1..4f6554aa6 100644 --- a/tests/endtoend/test_threadpool_thread__count_functions.py +++ b/tests/endtoend/test_threadpool_thread__count_functions.py @@ -7,63 +7,6 @@ from tests.utils import testutils -class TestPythonThreadpoolThreadCount1(testutils.WebHostTestCase): - """ Test the Http Trigger with setting up the python threadpool thread - count to 1.this test will check if both requests should not be processed - at the same time. this file is more focus on testing the E2E flow - scenarios. - """ - - @classmethod - def setUpClass(cls): - os_environ = os.environ.copy() - os_environ['PYTHON_THREADPOOL_THREAD_COUNT'] = '1' - cls._patch_environ = patch.dict('os.environ', os_environ) - cls._patch_environ.start() - super().setUpClass() - - def tearDown(self): - super().tearDown() - self._patch_environ.stop() - - @classmethod - def get_script_dir(cls): - return testutils.E2E_TESTS_FOLDER / 'http_functions' - - @testutils.retryable_test(3, 5) - def test_http_func_with_thread_count_1(self): - res = [None, None] - - def http_req(response_num): - r = self.webhost.request('GET', 'http_func') - self.assertTrue(r.ok) - res[response_num] = datetime.strptime( - r.content.decode("utf-8"), "%H:%M:%S") - - # creating 2 different threads to send parallel HTTP request - trd1 = Thread(target=http_req, args=(0,)) - trd2 = Thread(target=http_req, args=(1,)) - trd1.start() - trd2.start() - trd1.join() - trd2.join() - """function execution time difference between both HTTP request - should be greater than of equal to 1 since both the request should - not be processed at the same time because - PYTHON_THREADPOOL_THREAD_COUNT is 1. - """ - time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) - self.assertTrue(time_diff_in_seconds >= 1) - - -class TestPythonThreadpoolThreadCount1Stein(TestPythonThreadpoolThreadCount1): - - @classmethod - def get_script_dir(cls): - return testutils.E2E_TESTS_FOLDER / 'http_functions' / \ - 'http_functions_stein' - - class TestPythonThreadpoolThreadCount2(testutils.WebHostTestCase): """ Test the Http Trigger with setting up the python threadpool thread count to 2. this test will check if both requests should be processed diff --git a/tests/endtoend/test_worker_proccess_count_functions.py b/tests/endtoend/test_worker_proccess_count_functions.py index e6da0564a..00d6cee18 100644 --- a/tests/endtoend/test_worker_proccess_count_functions.py +++ b/tests/endtoend/test_worker_proccess_count_functions.py @@ -7,64 +7,6 @@ from tests.utils import testutils -class TestWorkerProcessCount1(testutils.WebHostTestCase): - """Test the Http Trigger with setting up the python worker process count - to 1. this test will check if both requests should not be processed at - the same time. this file is more focused on testing the E2E flow scenario - for FUNCTIONS_WORKER_PROCESS_COUNT feature. - """ - - @classmethod - def setUpClass(cls): - os_environ = os.environ.copy() - os_environ['PYTHON_THREADPOOL_THREAD_COUNT'] = '1' - os_environ['FUNCTIONS_WORKER_PROCESS_COUNT'] = '1' - cls._patch_environ = patch.dict('os.environ', os_environ) - cls._patch_environ.start() - super().setUpClass() - - def tearDown(self): - super().tearDown() - self._patch_environ.stop() - - @classmethod - def get_script_dir(cls): - return testutils.E2E_TESTS_FOLDER / 'http_functions' - - @testutils.retryable_test(3, 5) - def test_http_func_with_worker_process_count_1(self): - res = [None, None] - - def http_req(response_num): - r = self.webhost.request('GET', 'http_func') - self.assertTrue(r.ok) - res[response_num] = datetime.strptime( - r.content.decode("utf-8"), "%H:%M:%S") - - # creating 2 different threads to send HTTP request - trd1 = Thread(target=http_req, args=(0,)) - trd2 = Thread(target=http_req, args=(1,)) - trd1.start() - trd2.start() - trd1.join() - trd2.join() - """function execution time difference between both HTTP request - should be greater than of equal to 1 since both the request should - not be processed at the same time because - FUNCTIONS_WORKER_PROCESS_COUNT is 1. - """ - time_diff_in_seconds = abs((res[0] - res[1]).total_seconds()) - self.assertTrue(time_diff_in_seconds >= 1) - - -class TestWorkerProcessCount1Stein(TestWorkerProcessCount1): - - @classmethod - def get_script_dir(cls): - return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ - 'http_functions_stein' - - class TestWorkerProcessCount2(testutils.WebHostTestCase): """Test the Http Trigger with setting up the python worker process count to 2. this test will check if both requests should be processed at the From 120d639822c1ab52d49df6ef5ac6ec86aae1e2ad Mon Sep 17 00:00:00 2001 From: pdthummar <101662222+pdthummar@users.noreply.github.com> Date: Mon, 20 Feb 2023 10:45:07 -0600 Subject: [PATCH 9/9] addressed comments --- tests/endtoend/test_threadpool_thread__count_functions.py | 6 +++--- tests/endtoend/test_worker_proccess_count_functions.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/endtoend/test_threadpool_thread__count_functions.py b/tests/endtoend/test_threadpool_thread__count_functions.py index 4f6554aa6..42c33eaff 100644 --- a/tests/endtoend/test_threadpool_thread__count_functions.py +++ b/tests/endtoend/test_threadpool_thread__count_functions.py @@ -7,7 +7,7 @@ from tests.utils import testutils -class TestPythonThreadpoolThreadCount2(testutils.WebHostTestCase): +class TestPythonThreadpoolThreadCount(testutils.WebHostTestCase): """ Test the Http Trigger with setting up the python threadpool thread count to 2. this test will check if both requests should be processed at the same time. this file is more focus on testing the E2E flow @@ -31,7 +31,7 @@ def get_script_dir(cls): return testutils.E2E_TESTS_FOLDER / 'http_functions' @testutils.retryable_test(3, 5) - def test_http_func_with_thread_count_2(self): + def test_http_func_with_thread_count(self): response = [None, None] def http_req(res_num): @@ -55,7 +55,7 @@ def http_req(res_num): self.assertTrue(time_diff_in_seconds < 1) -class TestPythonThreadpoolThreadCount2Stein(TestPythonThreadpoolThreadCount2): +class TestPythonThreadpoolThreadCountStein(TestPythonThreadpoolThreadCount): @classmethod def get_script_dir(cls): diff --git a/tests/endtoend/test_worker_proccess_count_functions.py b/tests/endtoend/test_worker_proccess_count_functions.py index 00d6cee18..35e72fb48 100644 --- a/tests/endtoend/test_worker_proccess_count_functions.py +++ b/tests/endtoend/test_worker_proccess_count_functions.py @@ -7,7 +7,7 @@ from tests.utils import testutils -class TestWorkerProcessCount2(testutils.WebHostTestCase): +class TestWorkerProcessCount(testutils.WebHostTestCase): """Test the Http Trigger with setting up the python worker process count to 2. this test will check if both requests should be processed at the same time. this file is more focused on testing the E2E flow scenario for @@ -56,7 +56,7 @@ def http_req(res_num): self.assertTrue(time_diff_in_seconds < 1) -class TestWorkerProcessCount2Stein(TestWorkerProcessCount2): +class TestWorkerProcessCountStein(TestWorkerProcessCount): @classmethod def get_script_dir(cls):