-
Notifications
You must be signed in to change notification settings - Fork 107
add e2e tests for PYTHON_THREADPOOL_THREAD_COUNT and FUNCTIONS_WORKER_PROCESS_COUNT #1136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
265121b
add e2e test for PYTHON_THREADPOOL_THREAD_COUNT.
pdthummar 62cc9f3
update
pdthummar a9fad4a
add e2e test for FUNCTIONS_WORKER_PROCESS_COUNT.
pdthummar 8b44658
updated typo.
pdthummar 1a8f7ac
Merge branch 'dev' into pthummar/add_features_e2e_tests
pdthummar 3ee062a
Merge branch 'dev' into pthummar/add_features_e2e_tests
pdthummar 61dffd6
updated files.
pdthummar d4c8339
Merge branch 'dev' into pthummar/add_features_e2e_tests
pdthummar 468081d
removed trailing white spaces.
pdthummar 2829f6f
Merge branch 'dev' into pthummar/add_features_e2e_tests
pdthummar 12de8f3
addressed comments
pdthummar 9f593ce
removed tests for worker and threadpool count 1.
pdthummar 120d639
addressed comments
pdthummar 73fc3db
Merge branch 'dev' into pthummar/add_features_e2e_tests
pdthummar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get", | ||
"post" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 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 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 | ||
scenarios. | ||
""" | ||
|
||
@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(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() | ||
"""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) | ||
|
||
|
||
class TestPythonThreadpoolThreadCountStein(TestPythonThreadpoolThreadCount): | ||
|
||
@classmethod | ||
def get_script_dir(cls): | ||
return testutils.E2E_TESTS_FOLDER / 'http_functions' / \ | ||
'http_functions_stein' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# 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 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 | ||
FUNCTIONS_WORKER_PROCESS_COUNT feature. | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
os_environ = os.environ.copy() | ||
os_environ['PYTHON_THREADPOOL_THREAD_COUNT'] = '1' | ||
pdthummar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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() | ||
'''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 < 1) | ||
|
||
|
||
class TestWorkerProcessCountStein(TestWorkerProcessCount): | ||
|
||
@classmethod | ||
def get_script_dir(cls): | ||
return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ | ||
'http_functions_stein' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.