Skip to content

Commit

Permalink
fix: unique function names (#1557)
Browse files Browse the repository at this point in the history
* initial test fixes

* del function_app

* refactor variables into separate file e2e & unit tests

* refactor variables for all pipelines

* typo

* absolute paths

* run all db tests

* typo

---------

Co-authored-by: Victoria Hall <victoria.hall@microsoft.com>
  • Loading branch information
hallvictoria and Victoria Hall authored Aug 8, 2024
1 parent 296e3c6 commit 2f8f424
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 183 deletions.
5 changes: 2 additions & 3 deletions eng/ci/core-tools-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ resources:
ref: refs/tags/release

variables:
- template: /ci/variables/build.yml@eng
- template: /ci/variables/cfs.yml@eng
- group: python-integration-resources
- template: /eng/templates/utils/official-variables.yml@self

extends:
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
parameters:
Expand Down
4 changes: 1 addition & 3 deletions eng/ci/custom-image-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ resources:
ref: refs/tags/release

variables:
- template: /ci/variables/build.yml@eng
- template: /ci/variables/cfs.yml@eng
- group: python-integration-resources
- template: /eng/templates/utils/official-variables.yml@self

extends:
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
Expand Down
4 changes: 1 addition & 3 deletions eng/ci/docker-consumption-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ resources:
ref: refs/tags/release

variables:
- template: /ci/variables/build.yml@eng
- template: /ci/variables/cfs.yml@eng
- group: python-integration-resources
- template: /eng/templates/utils/official-variables.yml@self

extends:
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
Expand Down
4 changes: 1 addition & 3 deletions eng/ci/docker-dedicated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ resources:
ref: refs/tags/release

variables:
- template: /ci/variables/build.yml@eng
- template: /ci/variables/cfs.yml@eng
- group: python-integration-resources
- template: /eng/templates/utils/official-variables.yml@self

extends:
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
Expand Down
9 changes: 2 additions & 7 deletions eng/ci/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ resources:
ref: refs/tags/release

variables:
- template: /ci/variables/build.yml@eng
- template: /ci/variables/cfs.yml@eng
- group: python-integration-resources
- name: isSdkRelease
value: $[startsWith(variables['Build.SourceBranch'], 'refs/heads/sdk/')]
- name: isExtensionsRelease
value: $[startsWith(variables['Build.SourceBranch'], 'refs/heads/extensions/')]
- template: /eng/templates/utils/variables.yml@self
- template: /eng/templates/utils/official-variables.yml@self

extends:
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
Expand Down
5 changes: 2 additions & 3 deletions eng/ci/official-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ resources:
ref: refs/tags/release

variables:
- template: /ci/variables/build.yml@eng
- template: /ci/variables/cfs.yml@eng
- group: python-integration-resources
- template: /eng/templates/utils/variables.yml@self
- template: /eng/templates/utils/official-variables.yml@self

extends:
template: v1/1ES.Official.PipelineTemplate.yml@1es
Expand Down
5 changes: 1 addition & 4 deletions eng/ci/public-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ resources:
ref: refs/tags/release

variables:
- name: isSdkRelease
value: $[startsWith(variables['Build.SourceBranch'], 'refs/heads/sdk/')]
- name: isExtensionsRelease
value: $[startsWith(variables['Build.SourceBranch'], 'refs/heads/extensions/')]
- template: /eng/templates/utils/variables.yml@self

extends:
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
Expand Down
2 changes: 1 addition & 1 deletion eng/scripts/test-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
python -m pip install --upgrade pip
if [[ $2 != "3.7" ]]; then
python -m pip install -e $1/PythonExtensionArtifact
python -m pip install --pre -U -e .[test-http-v2]
python -m pip install --pre -e .[test-http-v2]
fi
if [[ $2 != "3.7" && $2 != "3.8" ]]; then
python -m pip install -e $1/PythonExtensionArtifact
Expand Down
2 changes: 1 addition & 1 deletion eng/scripts/test-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

python -m pip install --upgrade pip
python -m pip install -e $1/PythonSdkArtifact
python -m pip install -U -e .[dev]
python -m pip install -e .[dev]

if [[ $2 != "3.7" ]]; then
python -m pip install --pre -U -e .[test-http-v2]
Expand Down
2 changes: 1 addition & 1 deletion eng/templates/official/jobs/ci-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
displayName: 'Install test python extension, dependencies and the worker'
condition: or(eq(variables.isExtensionsRelease, true), eq(variables['USETESTPYTHONEXTENSIONS'], true))
- bash: |
python -m pytest -q -n auto --dist loadfile --reruns 4 --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend tests/extension_tests/deferred_bindings_tests/test_deferred_bindings_blob_functions.py tests/extension_tests/http_v2_tests
python -m pytest -q -n auto --dist loadfile --reruns 4 --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend tests/extension_tests/deferred_bindings_tests tests/extension_tests/http_v2_tests
env:
AzureWebJobsStorage: $(STORAGE_CONNECTION)
AzureWebJobsCosmosDBConnectionString: $(COSMOSDB_CONNECTION)
Expand Down
4 changes: 4 additions & 0 deletions eng/templates/utils/official-variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variables:
- template: /ci/variables/build.yml@eng
- template: /ci/variables/cfs.yml@eng
- group: python-integration-resources
5 changes: 5 additions & 0 deletions eng/templates/utils/variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variables:
- name: isSdkRelease
value: $[startsWith(variables['Build.SourceBranch'], 'refs/heads/sdk/')]
- name: isExtensionsRelease
value: $[startsWith(variables['Build.SourceBranch'], 'refs/heads/extensions/')]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import unittest

import azure.functions as func
from tests.utils import testutils

from azure_functions_worker import protos
Expand All @@ -20,6 +21,14 @@
'deferred_bindings_tests' / \
'deferred_bindings_functions' / \
'deferred_bindings_enabled'
DEFERRED_BINDINGS_DISABLED_DIR = testutils.EXTENSION_TESTS_FOLDER / \
'deferred_bindings_tests' / \
'deferred_bindings_functions' / \
'deferred_bindings_disabled'
DEFERRED_BINDINGS_ENABLED_DUAL_DIR = testutils.EXTENSION_TESTS_FOLDER / \
'deferred_bindings_tests' / \
'deferred_bindings_functions' / \
'deferred_bindings_enabled_dual'


class MockMBD:
Expand All @@ -35,6 +44,7 @@ def __init__(self, version: str, source: str,
"is only supported for 3.9+.")
class TestDeferredBindingsEnabled(testutils.AsyncTestCase):

@testutils.retryable_test(3, 5)
async def test_deferred_bindings_enabled_metadata(self):
async with testutils.start_mockhost(
script_root=DEFERRED_BINDINGS_ENABLED_DIR) as host:
Expand All @@ -43,7 +53,9 @@ async def test_deferred_bindings_enabled_metadata(self):
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertEqual(r.response.result.status,
protos.StatusResult.Success)
del sys.modules['function_app']

@testutils.retryable_test(3, 5)
async def test_deferred_bindings_enabled_log(self):
async with testutils.start_mockhost(
script_root=DEFERRED_BINDINGS_ENABLED_DIR) as host:
Expand All @@ -56,11 +68,74 @@ async def test_deferred_bindings_enabled_log(self):
enabled_log_present = True
break
self.assertTrue(enabled_log_present)
del sys.modules['function_app']


@unittest.skipIf(sys.version_info.minor <= 8, "The base extension"
"is only supported for 3.9+.")
class TestDeferredBindingsDisabled(testutils.AsyncTestCase):

@testutils.retryable_test(3, 5)
async def test_deferred_bindings_disabled_metadata(self):
async with testutils.start_mockhost(
script_root=DEFERRED_BINDINGS_DISABLED_DIR) as host:
await host.init_worker()
r = await host.get_functions_metadata()
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertEqual(r.response.result.status,
protos.StatusResult.Success)
del sys.modules['function_app']

@testutils.retryable_test(3, 5)
async def test_deferred_bindings_disabled_log(self):
async with testutils.start_mockhost(
script_root=DEFERRED_BINDINGS_DISABLED_DIR) as host:
await host.init_worker()
r = await host.get_functions_metadata()
disabled_log_present = False
for log in r.logs:
message = log.message
if "Deferred bindings enabled: False" in message:
disabled_log_present = True
break
self.assertTrue(disabled_log_present)
del sys.modules['function_app']


@unittest.skipIf(sys.version_info.minor <= 8, "The base extension"
"is only supported for 3.9+.")
class TestDeferredBindingsEnabledDual(testutils.AsyncTestCase):

@testutils.retryable_test(3, 5)
async def test_deferred_bindings_dual_metadata(self):
async with testutils.start_mockhost(
script_root=DEFERRED_BINDINGS_ENABLED_DUAL_DIR) as host:
await host.init_worker()
r = await host.get_functions_metadata()
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertEqual(r.response.result.status,
protos.StatusResult.Success)
del sys.modules['function_app']

@testutils.retryable_test(3, 5)
async def test_deferred_bindings_dual_enabled_log(self):
async with testutils.start_mockhost(
script_root=DEFERRED_BINDINGS_ENABLED_DUAL_DIR) as host:
await host.init_worker()
r = await host.get_functions_metadata()
enabled_log_present = False
for log in r.logs:
message = log.message
if "Deferred bindings enabled: True" in message:
enabled_log_present = True
break
self.assertTrue(enabled_log_present)
del sys.modules['function_app']


@unittest.skipIf(sys.version_info.minor <= 8, "The base extension"
"is only supported for 3.9+.")
class TestDeferredBindingsEnabledHelpers(testutils.AsyncTestCase):
class TestDeferredBindingsHelpers(testutils.AsyncTestCase):

def test_deferred_bindings_enabled_decode(self):
binding = BlobClientConverter
Expand Down Expand Up @@ -92,27 +167,31 @@ async def test_check_deferred_bindings_enabled(self):
The second represents if the current binding is deferred binding. If this is
True, then deferred bindings must also be enabled at the function level.
Test type 1: type is supported, deferred_bindings_enabled is not yet set
Test type 2: type is supported, deferred_bindings_enabled is already set
"""
async with testutils.start_mockhost(
script_root=DEFERRED_BINDINGS_ENABLED_DIR) as host:
await host.init_worker()
self.assertEqual(meta.check_deferred_bindings_enabled(
BlobClient, False), (True, True))

# Type is not supported, deferred_bindings_enabled is not yet set
self.assertEqual(meta.check_deferred_bindings_enabled(
BlobClient, True), (True, True))
func.InputStream, False), (False, False))

# Type is not supported, deferred_bindings_enabled already set
self.assertEqual(meta.check_deferred_bindings_enabled(
ContainerClient, False), (True, True))
func.InputStream, True), (True, False))

# Type is supported, deferred_bindings_enabled is not yet set
self.assertEqual(meta.check_deferred_bindings_enabled(
ContainerClient, True), (True, True))

BlobClient, False), (True, True))
self.assertEqual(meta.check_deferred_bindings_enabled(
ContainerClient, False), (True, True))
self.assertEqual(meta.check_deferred_bindings_enabled(
StorageStreamDownloader, False), (True, True))

# Type is supported, deferred_bindings_enabled is already set
self.assertEqual(meta.check_deferred_bindings_enabled(
BlobClient, True), (True, True))
self.assertEqual(meta.check_deferred_bindings_enabled(
ContainerClient, True), (True, True))
self.assertEqual(meta.check_deferred_bindings_enabled(
StorageStreamDownloader, True), (True, True))

This file was deleted.

Loading

0 comments on commit 2f8f424

Please sign in to comment.