Skip to content

Fixed unit and docker tests #1438

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 13 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_docker_con_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]
permissions: read-all
env:
CONSUMPTION_DOCKER_TEST: "true"
Expand Down
7 changes: 6 additions & 1 deletion tests/endtoend/test_file_name_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class TestHttpFunctionsFileName(testutils.WebHostTestCase):
@classmethod
def setUpClass(cls):
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "main.py"
cls.env_variables['PYTHON_SCRIPT_FILE_NAME'] = 'main.py'
super().setUpClass()

@classmethod
def tearDownClass(cls):
# Remove the WEBSITE_HOSTNAME environment variable
# Remove the PYTHON_SCRIPT_FILE_NAME environment variable
os.environ.pop('PYTHON_SCRIPT_FILE_NAME')
super().tearDownClass()

Expand All @@ -38,6 +39,10 @@ def get_script_dir(cls):
'http_functions_stein' / \
'file_name'

@classmethod
def get_environment_variables(cls):
return cls.env_variables

@testutils.retryable_test(3, 5)
def test_index_page_should_return_ok(self):
"""The index page of Azure Functions should return OK in any
Expand Down
14 changes: 9 additions & 5 deletions tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ async def test_dispatcher_sync_threadpool_default_worker(self):
correct default value
"""
async with self._ctrl as host:
# await self._check_if_function_is_ok(host)
await host.init_worker()
await self._check_if_function_is_ok(host)
await self._assert_workers_threadpool(self._ctrl, host,
self._default_workers)

Expand All @@ -154,6 +155,7 @@ async def test_dispatcher_sync_threadpool_set_worker(self):
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT:
f'{self._allowed_max_workers}'})
async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)
await self._assert_workers_threadpool(self._ctrl, host,
self._allowed_max_workers)
Expand Down Expand Up @@ -335,10 +337,11 @@ async def test_async_invocation_request_log(self):
)

async def test_sync_invocation_request_log_threads(self):
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '5'})

with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '5'})

async with self._ctrl as host:
await host.init_worker()
request_id: str = self._ctrl._worker._request_id
func_id, invoke_id, func_name = (
await self._check_if_function_is_ok(host)
Expand All @@ -359,10 +362,11 @@ async def test_sync_invocation_request_log_threads(self):
)

async def test_async_invocation_request_log_threads(self):
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '4'})

with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '4'})

async with self._ctrl as host:
await host.init_worker()
request_id: str = self._ctrl._worker._request_id
func_id, invoke_id, func_name = (
await self._check_if_async_function_is_ok(host)
Expand Down
3 changes: 3 additions & 0 deletions tests/unittests/test_enable_debug_logging_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
os.environ.pop(PYTHON_ENABLE_DEBUG_LOGGING)
super().tearDownClass()
cls._patch_environ.stop()

Expand Down Expand Up @@ -72,6 +73,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
os.environ.pop(PYTHON_ENABLE_DEBUG_LOGGING)
super().tearDownClass()
cls._patch_environ.stop()

Expand Down Expand Up @@ -118,6 +120,7 @@ def tearDownClass(cls):
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json'
remove_path(host_json)

os.environ.pop(PYTHON_ENABLE_DEBUG_LOGGING)
super().tearDownClass()
cls._patch_environ.stop()

Expand Down
38 changes: 20 additions & 18 deletions tests/unittests/test_invalid_stein.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import collections as col

from azure_functions_worker import protos
from tests.utils import testutils

SysVersionInfo = col.namedtuple("VersionInfo", ["major", "minor", "micro",
"releaselevel", "serial"])
STEIN_INVALID_APP_FUNCTIONS_DIR = testutils.UNIT_TESTS_FOLDER / \
'broken_functions' / \
'invalid_app_stein'
Expand All @@ -17,24 +13,30 @@

class TestInvalidAppStein(testutils.AsyncTestCase):

@testutils.retryable_test(4, 5)
async def test_indexing_not_app(self):
"""Test if the functions metadata response will be 0
when an invalid app is provided
"""
mock_host = testutils.start_mockhost(
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
async with mock_host as host:
"""Test if the functions metadata status will be
Failure when an invalid app is provided
"""
async with testutils.start_mockhost(
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR) as host:
await host.init_worker()
r = await host.get_functions_metadata()
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertIn("Error", r.response.result.exception.message)
self.assertEqual(r.response.result.status,
protos.StatusResult.Failure)
self.assertIsNotNone(r.response.result.exception.message)

@testutils.retryable_test(4, 5)
async def test_indexing_invalid_app(self):
"""Test if the functions metadata response will be 0
when an invalid app is provided
"""
mock_host = testutils.start_mockhost(
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
async with mock_host as host:
"""Test if the functions metadata status will be
Failure when an invalid app is provided
"""
async with testutils.start_mockhost(
script_root=STEIN_INVALID_FUNCTIONS_DIR) as host:
await host.init_worker()
r = await host.get_functions_metadata()
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertIn("Error", r.response.result.exception.message)
self.assertEqual(r.response.result.status,
protos.StatusResult.Failure)
self.assertIsNotNone(r.response.result.exception.message)