Skip to content
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

Fixing extension bundle and test utils #1115

Merged
merged 9 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/ut_ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: "Python UT CI Run"
runs-on: ubuntu-latest
strategy:
fail-fast: true
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
steps:
Expand Down
2 changes: 1 addition & 1 deletion azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ async def _handle__functions_metadata_request(self, request):
try:
fx_metadata_results = []
indexed_functions = loader.index_function_app(function_path)
logger.info('Indexed function app and found {} functions',
logger.info('Indexed function app and found %s functions',
len(indexed_functions))
if indexed_functions:
indexed_function_logs: List[str] = []
Expand Down
48 changes: 6 additions & 42 deletions azure_functions_worker/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,39 +70,14 @@
HOST_JSON_TEMPLATE = """\
{
"version": "2.0",
"logging": {"logLevel": {"default": "Trace"}}
"logging": {"logLevel": {"default": "Trace"}},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.15.0, 4.0.0)"
}
}
"""

EXTENSION_CSPROJ_TEMPLATE = """\
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<WarningsAsErrors></WarningsAsErrors>
<DefaultItemExcludes>**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs"
Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid"
Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB"
Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage"
Version="4.0.5" />
<PackageReference
Include="Microsoft.Azure.WebJobs.Extensions.Storage.Blobs"
Version="5.0.0" />
<PackageReference
Include="Microsoft.Azure.WebJobs.Extensions.Storage.Queues"
Version="5.0.0" />
<PackageReference
Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator"
Version="1.1.3" />
</ItemGroup>
</Project>
"""

SECRETS_TEMPLATE = """\
{
"masterKey": {
Expand Down Expand Up @@ -975,29 +950,18 @@ def _symlink_dir(src, dst):


def _setup_func_app(app_root):
extensions = app_root / 'bin'
host_json = app_root / 'host.json'
extensions_csproj_file = app_root / 'extensions.csproj'

if not os.path.isfile(host_json):
with open(host_json, 'w') as f:
f.write(HOST_JSON_TEMPLATE)

if not os.path.isfile(extensions_csproj_file):
with open(extensions_csproj_file, 'w') as f:
f.write(EXTENSION_CSPROJ_TEMPLATE)

_symlink_dir(EXTENSIONS_PATH, extensions)


def _teardown_func_app(app_root):
extensions = app_root / 'bin'
host_json = app_root / 'host.json'
extensions_csproj_file = app_root / 'extensions.csproj'
extensions_obj_file = app_root / 'obj'

for path in (extensions, host_json, extensions_csproj_file,
extensions_obj_file):
for path in (host_json, extensions_obj_file):
remove_path(path)


Expand Down
14 changes: 7 additions & 7 deletions tests/unittests/test_enable_debug_logging_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def setUpClass(cls):
super().setUpClass()

@classmethod
def tearDownClass(self):
def tearDownClass(cls):
super().tearDownClass()
self._patch_environ.stop()
cls._patch_environ.stop()

@classmethod
def get_script_dir(cls):
Expand Down Expand Up @@ -71,9 +71,9 @@ def setUpClass(cls):
super().setUpClass()

@classmethod
def tearDownClass(self):
def tearDownClass(cls):
super().tearDownClass()
self._patch_environ.stop()
cls._patch_environ.stop()

@classmethod
def get_script_dir(cls):
Expand Down Expand Up @@ -114,12 +114,12 @@ def setUpClass(cls):
super().setUpClass()

@classmethod
def tearDownClass(self):
host_json = TESTS_ROOT / self.get_script_dir() / 'host.json'
def tearDownClass(cls):
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json'
remove_path(host_json)

super().tearDownClass()
self._patch_environ.stop()
cls._patch_environ.stop()

@classmethod
def get_script_dir(cls):
Expand Down
55 changes: 5 additions & 50 deletions tests/unittests/test_utilities_dependency.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import importlib.util
import os
import sys
import importlib.util
import unittest
from unittest.mock import patch

from azure_functions_worker import testutils
from azure_functions_worker.utils.common import is_python_version
from azure_functions_worker.utils.dependency import DependencyManager


Expand Down Expand Up @@ -555,12 +554,8 @@ def test_use_worker_dependencies_disable(self):
with self.assertRaises(ImportError):
import common_module # NoQA

@unittest.skipUnless(
sys.version_info.major == 3 and sys.version_info.minor != 10,
'Test only available for Python 3.6, 3.7, 3.8 or 3.9'
)
def test_use_worker_dependencies_default_python_36_37_38_39(self):
# Feature should be disabled in Python 3.6, 3.7, 3.8 and 3.9
def test_use_worker_dependencies_default_python_all_versions(self):
# Feature should be disabled for all python versions
# Setup paths
DependencyManager.worker_deps_path = self._worker_deps_path
DependencyManager.cx_deps_path = self._customer_deps_path
Expand All @@ -571,25 +566,6 @@ def test_use_worker_dependencies_default_python_36_37_38_39(self):
with self.assertRaises(ImportError):
import common_module # NoQA

@unittest.skipUnless(
sys.version_info.major == 3 and sys.version_info.minor == 10,
'Test only available for Python 3.10'
)
def test_use_worker_dependencies_default_python_310(self):
# Feature should be enabled in Python 3.10 by default
# Setup paths
DependencyManager.worker_deps_path = self._worker_deps_path
DependencyManager.cx_deps_path = self._customer_deps_path
DependencyManager.cx_working_dir = self._customer_func_path

# Ensure the common_module is imported from _worker_deps_path
DependencyManager.use_worker_dependencies()
import common_module # NoQA
self.assertEqual(
common_module.package_location,
os.path.join(self._worker_deps_path, 'common_module')
)

def test_prioritize_customer_dependencies(self):
# Setup app settings
os.environ['PYTHON_ISOLATE_WORKER_DEPENDENCIES'] = 'true'
Expand Down Expand Up @@ -628,10 +604,8 @@ def test_prioritize_customer_dependencies_disable(self):
with self.assertRaises(ImportError):
import common_module # NoQA

@unittest.skipIf(is_python_version('3.10'),
'Test not available for python 3.10')
def test_prioritize_customer_dependencies_default_python_36_37_38_39(self):
# Feature should be disabled in Python 3.6, 3.7, 3.8 and 3.9
def test_prioritize_customer_dependencies_default_all_versions(self):
# Feature should be disabled in Python for all versions
# Setup paths
DependencyManager.worker_deps_path = self._worker_deps_path
DependencyManager.cx_deps_path = self._customer_deps_path
Expand All @@ -642,25 +616,6 @@ def test_prioritize_customer_dependencies_default_python_36_37_38_39(self):
with self.assertRaises(ImportError):
import common_module # NoQA

@unittest.skipUnless(
sys.version_info.major == 3 and sys.version_info.minor == 10,
'Test only available for Python 3.10'
)
def test_prioritize_customer_dependencies_default_python_310(self):
# Feature should be enabled in Python 3.10 by default
# Setup paths
DependencyManager.worker_deps_path = self._worker_deps_path
DependencyManager.cx_deps_path = self._customer_deps_path
DependencyManager.cx_working_dir = self._customer_func_path

# Ensure the common_module is imported from _customer_deps_path
DependencyManager.prioritize_customer_dependencies()
import common_module # NoQA
self.assertEqual(
common_module.package_location,
os.path.join(self._customer_deps_path, 'common_module')
)

def test_prioritize_customer_dependencies_from_working_directory(self):
self._initialize_scenario()

Expand Down