Skip to content

Commit f73300b

Browse files
authored
Add warmup trigger e2e tests (#1295)
* add warmup trigger e2e tests
1 parent 222883c commit f73300b

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import typing
5+
6+
from tests.utils import testutils
7+
8+
9+
class TestWarmupFunctions(testutils.WebHostTestCase):
10+
"""Test the Warmup Trigger in the local webhost.
11+
12+
This test class will spawn a webhost from your <project_root>/build/webhost
13+
folder and replace the built-in Python with azure_functions_worker from
14+
your code base. This test is more focused on testing e2e scenario for
15+
warmup trigger function.
16+
17+
"""
18+
19+
@classmethod
20+
def get_script_dir(cls):
21+
return testutils.E2E_TESTS_FOLDER / 'warmup_functions'
22+
23+
def test_warmup(self):
24+
r = self.webhost.request('GET', 'admin/warmup', no_prefix=True)
25+
26+
self.assertTrue(r.ok)
27+
28+
def check_log_warmup(self, host_out: typing.List[str]):
29+
self.assertEqual(host_out.count("Function App instance is warm"), 1)
30+
31+
32+
class TestWarmupFunctionsStein(TestWarmupFunctions):
33+
34+
@classmethod
35+
def get_script_dir(cls):
36+
return testutils.E2E_TESTS_FOLDER / 'warmup_functions' / \
37+
'warmup_functions_stein'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import logging
5+
6+
7+
def main(warmupContext) -> None:
8+
logging.info('Function App instance is warm')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "warmupTrigger",
5+
"direction": "in",
6+
"name": "warmupContext"
7+
}
8+
]
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import azure.functions as func
5+
import logging
6+
7+
app = func.FunctionApp()
8+
9+
10+
@app.warm_up_trigger('warmup')
11+
def warmup(warmup) -> None:
12+
logging.info('Function App instance is warm')

0 commit comments

Comments
 (0)