diff --git a/tests/endtoend/test_warmup_functions.py b/tests/endtoend/test_warmup_functions.py new file mode 100644 index 000000000..d2dd4a0aa --- /dev/null +++ b/tests/endtoend/test_warmup_functions.py @@ -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 /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' diff --git a/tests/endtoend/warmup_functions/warmup/__init__.py b/tests/endtoend/warmup_functions/warmup/__init__.py new file mode 100644 index 000000000..0d186eab6 --- /dev/null +++ b/tests/endtoend/warmup_functions/warmup/__init__.py @@ -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') diff --git a/tests/endtoend/warmup_functions/warmup/function.json b/tests/endtoend/warmup_functions/warmup/function.json new file mode 100644 index 000000000..04c3f9d07 --- /dev/null +++ b/tests/endtoend/warmup_functions/warmup/function.json @@ -0,0 +1,9 @@ +{ + "bindings": [ + { + "type": "warmupTrigger", + "direction": "in", + "name": "warmupContext" + } + ] +} \ No newline at end of file diff --git a/tests/endtoend/warmup_functions/warmup_functions_stein/function_app.py b/tests/endtoend/warmup_functions/warmup_functions_stein/function_app.py new file mode 100644 index 000000000..371820976 --- /dev/null +++ b/tests/endtoend/warmup_functions/warmup_functions_stein/function_app.py @@ -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')