Skip to content
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
4 changes: 2 additions & 2 deletions tests/endtoend/test_http_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_function_index_page_should_return_ok(self):
"""The index page of Azure Functions should return OK in any
circumstances
"""
root_url = self.webhost._addr
r = requests.get(root_url, timeout=REQUEST_TIMEOUT_SEC)
r = self.webhost.request('GET', '', no_prefix=True,
timeout=REQUEST_TIMEOUT_SEC)
self.assertTrue(r.ok)

@testutils.retryable_test(3, 5)
Expand Down
43 changes: 43 additions & 0 deletions tests/endtoend/test_timer_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import time
import typing
from tests.utils import testutils

REQUEST_TIMEOUT_SEC = 5


class TestTimerFunctions(testutils.WebHostTestCase):
"""Test the Timer 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. Since the Timer Trigger is a native support from host, we
don't need to setup any external resources.

Compared to the unittests/test_timer_functions.py, this file is more focus
on testing the E2E flow scenarios.
"""

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

def test_timer(self):
time.sleep(1)
# Checking webhost status.
r = self.webhost.request('GET', '', no_prefix=True,
timeout=REQUEST_TIMEOUT_SEC)
self.assertTrue(r.ok)

def check_log_timer(self, host_out: typing.List[str]):
self.assertEqual(host_out.count("This timer trigger function executed "
"successfully"), 1)


class TestTimerFunctionsStein(TestTimerFunctions):

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

import logging

import azure.functions as func


def main(mytimer: func.TimerRequest) -> None:
logging.info("This timer trigger function executed successfully")
12 changes: 12 additions & 0 deletions tests/endtoend/timer_functions/timer_func/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "*/1 * * * * *",
"runOnStartup": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import logging

import azure.functions as func

app = func.FunctionApp()


@app.function_name(name="mytimer")
@app.schedule(schedule="*/1 * * * * *", arg_name="mytimer",
run_on_startup=False,
use_monitor=False)
def mytimer(mytimer: func.TimerRequest) -> None:
logging.info("This timer trigger function executed successfully")