Skip to content

Commit b97a4ad

Browse files
authored
Test Fixes for 503 error (#1433)
* 503 tests fixes * Flake8 fixes * Disabling extensions for http * Fixed docker tests * Updated e2e test for file_name * Changing scope for running unit tests * Updated invalid stein testscases * Reverting to pytest loadfile * Updating extensions * Closing host before cleanup * Calling teardownclass directly from except block * Fixed flake8 validation * Reverting disabling extensions * Changing the order of install extensions * Removing the EnableWorkerIndexing flag * Changed target framework * Raising error if webhost fails to start * Added Azure messaging eh and eg to extension.csproj * Removing dockerfile * Moving extensions template to constants.py * Minor fixes * Skipping installing extensions for unit tests * Updating target framework * Addressed comments
1 parent 3dd54af commit b97a4ad

12 files changed

+163
-149
lines changed

.github/workflows/ci_docker_con_workflow.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ jobs:
8080
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
8181
run: |
8282
python -m pytest --reruns 4 -vv --instafail tests/endtoend
83+
- name: Running 3.11 Tests
84+
if: matrix.python-version == 3.11
85+
env:
86+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString311 }}
87+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString311 }}
88+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString311 }}
89+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString311 }}
90+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString311 }}
91+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString311 }}
92+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString311 }}
93+
run: |
94+
python -m pytest --reruns 4 -vv --instafail tests/endtoend

.github/workflows/ci_docker_ded_workflow.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
19+
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]
2020
permissions: read-all
2121
env:
2222
DEDICATED_DOCKER_TEST: "true"
@@ -80,3 +80,16 @@ jobs:
8080
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
8181
run: |
8282
python -m pytest --reruns 4 -vv --instafail tests/endtoend
83+
- name: Running 3.11 Tests
84+
if: matrix.python-version == 3.11
85+
env:
86+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString311 }}
87+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString311 }}
88+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString311 }}
89+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString311 }}
90+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString311 }}
91+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString311 }}
92+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString311 }}
93+
run: |
94+
python -m pytest --reruns 4 -vv --instafail tests/endtoend
95+

.github/workflows/ci_ut_workflow.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
# Retry a couple times to avoid certificate issue
6464
retry 5 python setup.py build
6565
retry 5 python setup.py webhost --branch-name=dev
66-
retry 5 python setup.py extension
6766
mkdir logs
6867
- name: Test with pytest
6968
env:

azure_functions_worker/loader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""Python functions loader."""
44
import importlib
55
import importlib.machinery
6-
import importlib.util
76
import os
87
import os.path
98
import pathlib

azure_functions_worker/utils/dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
import importlib
3+
import importlib.util
44
import inspect
55
import os
66
import re

setup.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,12 @@
2121
from setuptools.command import develop
2222

2323
from azure_functions_worker.version import VERSION
24+
from tests.utils.constants import EXTENSIONS_CSPROJ_TEMPLATE
2425

2526
# The GitHub repository of the Azure Functions Host
2627
WEBHOST_GITHUB_API = "https://api.github.com/repos/Azure/azure-functions-host"
2728
WEBHOST_TAG_PREFIX = "v4."
2829
WEBHOST_GIT_REPO = "https://github.com/Azure/azure-functions-host/archive"
29-
30-
# Extensions necessary for non-core bindings.
31-
AZURE_EXTENSIONS = """\
32-
<?xml version="1.0" encoding="UTF-8"?>
33-
<Project Sdk="Microsoft.NET.Sdk">
34-
<PropertyGroup>
35-
<TargetFramework>netcoreapp3.1</TargetFramework>
36-
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
37-
<WarningsAsErrors />
38-
<DefaultItemExcludes>**</DefaultItemExcludes>
39-
</PropertyGroup>
40-
<ItemGroup>
41-
<PackageReference Include="Microsoft.NET.Sdk.Functions"
42-
Version="4.0.1" />
43-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB"
44-
Version="4.2.0" />
45-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs"
46-
Version="5.0.0" />
47-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid"
48-
Version="3.3.1" />
49-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage"
50-
Version="4.0.5" />
51-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus"
52-
Version="4.2.1" />
53-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Sql"
54-
Version="0.1.346-preview" />
55-
<PackageReference
56-
Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator"
57-
Version="1.1.3" />
58-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask"
59-
Version="2.9.4" />
60-
</ItemGroup>
61-
</Project>
62-
"""
63-
6430
NUGET_CONFIG = """\
6531
<?xml version="1.0" encoding="UTF-8"?>
6632
<configuration>
@@ -277,7 +243,7 @@ def _install_extensions(self):
277243

278244
if not (self.extensions_dir / "extensions.csproj").exists():
279245
with open(self.extensions_dir / "extensions.csproj", "w") as f:
280-
print(AZURE_EXTENSIONS, file=f)
246+
print(EXTENSIONS_CSPROJ_TEMPLATE, file=f)
281247

282248
with open(self.extensions_dir / "NuGet.config", "w") as f:
283249
print(NUGET_CONFIG, file=f)

tests/endtoend/test_file_name_functions.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ class TestHttpFunctionsFileName(testutils.WebHostTestCase):
2020
Compared to the unittests/test_http_functions.py, this file is more focus
2121
on testing the E2E flow scenarios.
2222
"""
23+
24+
@classmethod
25+
def setUpClass(cls):
26+
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "main.py"
27+
super().setUpClass()
28+
2329
@classmethod
24-
def get_script_name(cls):
25-
return "main.py"
30+
def tearDownClass(cls):
31+
# Remove the WEBSITE_HOSTNAME environment variable
32+
os.environ.pop('PYTHON_SCRIPT_FILE_NAME')
33+
super().tearDownClass()
2634

2735
@classmethod
2836
def get_script_dir(cls):

tests/unittests/test_invalid_stein.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
import collections as col
4-
import os
5-
from unittest.mock import patch
64

75
from azure_functions_worker import protos
86
from tests.utils import testutils
@@ -19,51 +17,24 @@
1917

2018
class TestInvalidAppStein(testutils.AsyncTestCase):
2119

22-
def setUp(self):
23-
self._ctrl = testutils.start_mockhost(
24-
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
25-
self._pre_env = dict(os.environ)
26-
self.mock_version_info = patch(
27-
'azure_functions_worker.dispatcher.sys.version_info',
28-
SysVersionInfo(3, 9, 0, 'final', 0))
29-
self.mock_version_info.start()
30-
31-
def tearDown(self):
32-
os.environ.clear()
33-
os.environ.update(self._pre_env)
34-
self.mock_version_info.stop()
35-
3620
async def test_indexing_not_app(self):
3721
"""Test if the functions metadata response will be 0
3822
when an invalid app is provided
3923
"""
40-
async with self._ctrl as host:
24+
mock_host = testutils.start_mockhost(
25+
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
26+
async with mock_host as host:
4127
r = await host.get_functions_metadata()
4228
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
4329
self.assertIn("Error", r.response.result.exception.message)
4430

45-
46-
class TestInvalidStein(testutils.AsyncTestCase):
47-
48-
def setUp(self):
49-
self._ctrl = testutils.start_mockhost(
50-
script_root=STEIN_INVALID_FUNCTIONS_DIR)
51-
self._pre_env = dict(os.environ)
52-
self.mock_version_info = patch(
53-
'azure_functions_worker.dispatcher.sys.version_info',
54-
SysVersionInfo(3, 9, 0, 'final', 0))
55-
self.mock_version_info.start()
56-
57-
def tearDown(self):
58-
os.environ.clear()
59-
os.environ.update(self._pre_env)
60-
self.mock_version_info.stop()
61-
6231
async def test_indexing_invalid_app(self):
6332
"""Test if the functions metadata response will be 0
6433
when an invalid app is provided
6534
"""
66-
async with self._ctrl as host:
35+
mock_host = testutils.start_mockhost(
36+
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
37+
async with mock_host as host:
6738
r = await host.get_functions_metadata()
6839
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
6940
self.assertIn("Error", r.response.result.exception.message)

tests/unittests/test_script_file_name.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ class TestDefaultScriptFileName(testutils.WebHostTestCase):
2525
"""
2626

2727
@classmethod
28-
def get_script_name(cls):
29-
return "function_app.py"
28+
def setUpClass(cls):
29+
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "function_app.py"
30+
super().setUpClass()
31+
32+
@classmethod
33+
def tearDownClass(cls):
34+
# Remove the PYTHON_SCRIPT_FILE_NAME environment variable
35+
os.environ.pop('PYTHON_SCRIPT_FILE_NAME')
36+
super().tearDownClass()
3037

3138
@classmethod
3239
def get_script_dir(cls):
@@ -47,12 +54,19 @@ class TestNewScriptFileName(testutils.WebHostTestCase):
4754
"""
4855

4956
@classmethod
50-
def get_script_dir(cls):
51-
return NEW_SCRIPT_FILE_NAME_DIR
57+
def setUpClass(cls):
58+
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "test.py"
59+
super().setUpClass()
5260

5361
@classmethod
54-
def get_script_name(cls):
55-
return "test.py"
62+
def tearDownClass(cls):
63+
# Remove the PYTHON_SCRIPT_FILE_NAME environment variable
64+
os.environ.pop('PYTHON_SCRIPT_FILE_NAME')
65+
super().tearDownClass()
66+
67+
@classmethod
68+
def get_script_dir(cls):
69+
return NEW_SCRIPT_FILE_NAME_DIR
5670

5771
def test_new_file_name(self):
5872
"""
@@ -69,12 +83,19 @@ class TestInvalidScriptFileName(testutils.WebHostTestCase):
6983
"""
7084

7185
@classmethod
72-
def get_script_dir(cls):
73-
return INVALID_SCRIPT_FILE_NAME_DIR
86+
def setUpClass(cls):
87+
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "main"
88+
super().setUpClass()
7489

7590
@classmethod
76-
def get_script_name(cls):
77-
return "main"
91+
def tearDownClass(cls):
92+
# Remove the PYTHON_SCRIPT_FILE_NAME environment variable
93+
os.environ.pop('PYTHON_SCRIPT_FILE_NAME')
94+
super().tearDownClass()
95+
96+
@classmethod
97+
def get_script_dir(cls):
98+
return INVALID_SCRIPT_FILE_NAME_DIR
7899

79100
def test_invalid_file_name(self):
80101
"""

tests/utils/constants.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,44 @@
22
# Licensed under the MIT License.
33
import pathlib
44

5+
# Extensions necessary for non-core bindings.
6+
EXTENSIONS_CSPROJ_TEMPLATE = """\
7+
<?xml version="1.0" encoding="UTF-8"?>
8+
<Project Sdk="Microsoft.NET.Sdk">
9+
<PropertyGroup>
10+
<TargetFramework>netcoreapp3.1</TargetFramework>
11+
<WarningsAsErrors></WarningsAsErrors>
12+
<DefaultItemExcludes>**</DefaultItemExcludes>
13+
</PropertyGroup>
14+
<ItemGroup>
15+
<PackageReference Include="Azure.Messaging.EventHubs"
16+
Version="5.6.2" />
17+
<PackageReference Include="Azure.Messaging.EventGrid"
18+
Version="4.21.0" />
19+
<PackageReference Include="Microsoft.NET.Sdk.Functions"
20+
Version="4.0.1" />
21+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB"
22+
Version="4.2.0" />
23+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs"
24+
Version="5.0.0" />
25+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid"
26+
Version="3.3.1" />
27+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage"
28+
Version="4.0.5" />
29+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus"
30+
Version="4.2.1" />
31+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Sql"
32+
Version="0.1.346-preview" />
33+
<PackageReference
34+
Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator"
35+
Version="1.1.3" />
36+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask"
37+
Version="2.9.4" />
38+
</ItemGroup>
39+
</Project>
40+
"""
41+
42+
543
# PROJECT_ROOT refers to the path to azure-functions-python-worker
644
# TODO: Find root folder without .parent
745
PROJECT_ROOT = pathlib.Path(__file__).parent.parent.parent

0 commit comments

Comments
 (0)