Skip to content

Test Fixes for 503 error #1433

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 24 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1d36c5e
503 tests fixes
gavin-aguiar Feb 15, 2024
7778c5f
Flake8 fixes
gavin-aguiar Feb 15, 2024
60c7690
Disabling extensions for http
gavin-aguiar Feb 16, 2024
c237ba2
Fixed docker tests
gavin-aguiar Feb 16, 2024
66eb89e
Updated e2e test for file_name
gavin-aguiar Feb 16, 2024
7b495ee
Changing scope for running unit tests
gavin-aguiar Feb 16, 2024
3e268ea
Updated invalid stein testscases
gavin-aguiar Feb 16, 2024
ad055c9
Reverting to pytest loadfile
gavin-aguiar Feb 20, 2024
71a4c06
Updating extensions
gavin-aguiar Feb 20, 2024
c46f3ed
Closing host before cleanup
gavin-aguiar Feb 20, 2024
8dcdca8
Calling teardownclass directly from except block
gavin-aguiar Feb 20, 2024
03d954b
Fixed flake8 validation
gavin-aguiar Feb 20, 2024
cdd9f43
Reverting disabling extensions
gavin-aguiar Feb 20, 2024
da115c1
Changing the order of install extensions
gavin-aguiar Feb 21, 2024
fa30d84
Removing the EnableWorkerIndexing flag
gavin-aguiar Feb 21, 2024
be06b87
Changed target framework
gavin-aguiar Feb 21, 2024
c30466d
Raising error if webhost fails to start
gavin-aguiar Feb 21, 2024
b0f2249
Added Azure messaging eh and eg to extension.csproj
gavin-aguiar Feb 23, 2024
91ecbc0
Removing dockerfile
gavin-aguiar Feb 26, 2024
3bb30a6
Moving extensions template to constants.py
gavin-aguiar Feb 26, 2024
222efff
Minor fixes
gavin-aguiar Feb 26, 2024
32c4545
Skipping installing extensions for unit tests
gavin-aguiar Feb 29, 2024
addefd8
Updating target framework
gavin-aguiar Feb 29, 2024
943b68f
Addressed comments
gavin-aguiar Feb 29, 2024
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
12 changes: 12 additions & 0 deletions .github/workflows/ci_docker_con_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,15 @@ jobs:
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
run: |
python -m pytest --reruns 4 -vv --instafail tests/endtoend
- name: Running 3.11 Tests
if: matrix.python-version == 3.11
env:
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString311 }}
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString311 }}
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString311 }}
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString311 }}
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString311 }}
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString311 }}
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString311 }}
run: |
python -m pytest --reruns 4 -vv --instafail tests/endtoend
15 changes: 14 additions & 1 deletion .github/workflows/ci_docker_ded_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:
DEDICATED_DOCKER_TEST: "true"
Expand Down Expand Up @@ -80,3 +80,16 @@ jobs:
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
run: |
python -m pytest --reruns 4 -vv --instafail tests/endtoend
- name: Running 3.11 Tests
if: matrix.python-version == 3.11
env:
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString311 }}
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString311 }}
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString311 }}
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString311 }}
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString311 }}
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString311 }}
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString311 }}
run: |
python -m pytest --reruns 4 -vv --instafail tests/endtoend

1 change: 0 additions & 1 deletion .github/workflows/ci_ut_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
# Retry a couple times to avoid certificate issue
retry 5 python setup.py build
retry 5 python setup.py webhost --branch-name=dev
retry 5 python setup.py extension
mkdir logs
- name: Test with pytest
env:
Expand Down
1 change: 0 additions & 1 deletion azure_functions_worker/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Python functions loader."""
import importlib
import importlib.machinery
import importlib.util
import os
import os.path
import pathlib
Expand Down
2 changes: 1 addition & 1 deletion azure_functions_worker/utils/dependency.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import importlib
import importlib.util
import inspect
import os
import re
Expand Down
38 changes: 2 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,12 @@
from setuptools.command import develop

from azure_functions_worker.version import VERSION
from tests.utils.constants import EXTENSIONS_CSPROJ_TEMPLATE

# The GitHub repository of the Azure Functions Host
WEBHOST_GITHUB_API = "https://github.com/api/repos/Azure/azure-functions-host"
WEBHOST_TAG_PREFIX = "v4."
WEBHOST_GIT_REPO = "https://github.com/Azure/azure-functions-host/archive"

# Extensions necessary for non-core bindings.
AZURE_EXTENSIONS = """\
<?xml version="1.0" encoding="UTF-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<WarningsAsErrors />
<DefaultItemExcludes>**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions"
Version="4.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB"
Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs"
Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid"
Version="3.3.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage"
Version="4.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus"
Version="4.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Sql"
Version="0.1.346-preview" />
<PackageReference
Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator"
Version="1.1.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask"
Version="2.9.4" />
</ItemGroup>
</Project>
"""

NUGET_CONFIG = """\
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
Expand Down Expand Up @@ -277,7 +243,7 @@ def _install_extensions(self):

if not (self.extensions_dir / "extensions.csproj").exists():
with open(self.extensions_dir / "extensions.csproj", "w") as f:
print(AZURE_EXTENSIONS, file=f)
print(EXTENSIONS_CSPROJ_TEMPLATE, file=f)

with open(self.extensions_dir / "NuGet.config", "w") as f:
print(NUGET_CONFIG, file=f)
Expand Down
12 changes: 10 additions & 2 deletions tests/endtoend/test_file_name_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ class TestHttpFunctionsFileName(testutils.WebHostTestCase):
Compared to the unittests/test_http_functions.py, this file is more focus
on testing the E2E flow scenarios.
"""

@classmethod
def setUpClass(cls):
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "main.py"
super().setUpClass()

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

@classmethod
def get_script_dir(cls):
Expand Down
41 changes: 6 additions & 35 deletions tests/unittests/test_invalid_stein.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import collections as col
import os
from unittest.mock import patch

from azure_functions_worker import protos
from tests.utils import testutils
Expand All @@ -19,51 +17,24 @@

class TestInvalidAppStein(testutils.AsyncTestCase):

def setUp(self):
self._ctrl = testutils.start_mockhost(
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
self._pre_env = dict(os.environ)
self.mock_version_info = patch(
'azure_functions_worker.dispatcher.sys.version_info',
SysVersionInfo(3, 9, 0, 'final', 0))
self.mock_version_info.start()

def tearDown(self):
os.environ.clear()
os.environ.update(self._pre_env)
self.mock_version_info.stop()

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


class TestInvalidStein(testutils.AsyncTestCase):

def setUp(self):
self._ctrl = testutils.start_mockhost(
script_root=STEIN_INVALID_FUNCTIONS_DIR)
self._pre_env = dict(os.environ)
self.mock_version_info = patch(
'azure_functions_worker.dispatcher.sys.version_info',
SysVersionInfo(3, 9, 0, 'final', 0))
self.mock_version_info.start()

def tearDown(self):
os.environ.clear()
os.environ.update(self._pre_env)
self.mock_version_info.stop()

async def test_indexing_invalid_app(self):
"""Test if the functions metadata response will be 0
when an invalid app is provided
"""
async with self._ctrl as host:
mock_host = testutils.start_mockhost(
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
async with mock_host as host:
r = await host.get_functions_metadata()
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertIn("Error", r.response.result.exception.message)
41 changes: 31 additions & 10 deletions tests/unittests/test_script_file_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ class TestDefaultScriptFileName(testutils.WebHostTestCase):
"""

@classmethod
def get_script_name(cls):
return "function_app.py"
def setUpClass(cls):
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "function_app.py"
super().setUpClass()

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

@classmethod
def get_script_dir(cls):
Expand All @@ -47,12 +54,19 @@ class TestNewScriptFileName(testutils.WebHostTestCase):
"""

@classmethod
def get_script_dir(cls):
return NEW_SCRIPT_FILE_NAME_DIR
def setUpClass(cls):
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "test.py"
super().setUpClass()

@classmethod
def get_script_name(cls):
return "test.py"
def tearDownClass(cls):
# Remove the PYTHON_SCRIPT_FILE_NAME environment variable
os.environ.pop('PYTHON_SCRIPT_FILE_NAME')
super().tearDownClass()

@classmethod
def get_script_dir(cls):
return NEW_SCRIPT_FILE_NAME_DIR

def test_new_file_name(self):
"""
Expand All @@ -69,12 +83,19 @@ class TestInvalidScriptFileName(testutils.WebHostTestCase):
"""

@classmethod
def get_script_dir(cls):
return INVALID_SCRIPT_FILE_NAME_DIR
def setUpClass(cls):
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "main"
super().setUpClass()

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

@classmethod
def get_script_dir(cls):
return INVALID_SCRIPT_FILE_NAME_DIR

def test_invalid_file_name(self):
"""
Expand Down
38 changes: 38 additions & 0 deletions tests/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@
# Licensed under the MIT License.
import pathlib

# Extensions necessary for non-core bindings.
EXTENSIONS_CSPROJ_TEMPLATE = """\
<?xml version="1.0" encoding="UTF-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<WarningsAsErrors></WarningsAsErrors>
<DefaultItemExcludes>**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.EventHubs"
Version="5.6.2" />
<PackageReference Include="Azure.Messaging.EventGrid"
Version="4.21.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions"
Version="4.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB"
Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs"
Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid"
Version="3.3.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage"
Version="4.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus"
Version="4.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Sql"
Version="0.1.346-preview" />
<PackageReference
Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator"
Version="1.1.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask"
Version="2.9.4" />
</ItemGroup>
</Project>
"""


# PROJECT_ROOT refers to the path to azure-functions-python-worker
# TODO: Find root folder without .parent
PROJECT_ROOT = pathlib.Path(__file__).parent.parent.parent
Expand Down
Loading