Skip to content

Add warmup trigger e2e tests #1295

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 3 commits into from
Aug 2, 2023
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
37 changes: 37 additions & 0 deletions tests/endtoend/test_warmup_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import typing

from tests.utils import testutils


class TestWarmupFunctions(testutils.WebHostTestCase):
"""Test the Warmup Trigger in the local webhost.

This test class will spawn a webhost from your <project_root>/build/webhost
folder and replace the built-in Python with azure_functions_worker from
your code base. This test is more focused on testing e2e scenario for
warmup trigger function.

"""

@classmethod
def get_script_dir(cls):
return testutils.E2E_TESTS_FOLDER / 'warmup_functions'

def test_warmup(self):
r = self.webhost.request('GET', 'admin/warmup', no_prefix=True)

self.assertTrue(r.ok)

def check_log_warmup(self, host_out: typing.List[str]):
self.assertEqual(host_out.count("Function App instance is warm"), 1)


class TestWarmupFunctionsStein(TestWarmupFunctions):

@classmethod
def get_script_dir(cls):
return testutils.E2E_TESTS_FOLDER / 'warmup_functions' / \
'warmup_functions_stein'
8 changes: 8 additions & 0 deletions tests/endtoend/warmup_functions/warmup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import logging


def main(warmupContext) -> None:
logging.info('Function App instance is warm')
9 changes: 9 additions & 0 deletions tests/endtoend/warmup_functions/warmup/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bindings": [
{
"type": "warmupTrigger",
"direction": "in",
"name": "warmupContext"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import azure.functions as func
import logging

app = func.FunctionApp()


@app.warm_up_trigger('warmup')
def warmup(warmup) -> None:
logging.info('Function App instance is warm')