Skip to content

Commit 02e5b12

Browse files
gavin-aguiarGavin Aguiar
and
Gavin Aguiar
authored
Adding docker tests (#1157)
* Adding docker tests * Added github workflows * Updated constants * Moved constants to test dir Co-authored-by: Gavin Aguiar <gavin@GavinPC>
1 parent b2a0bf6 commit 02e5b12

File tree

10 files changed

+385
-12
lines changed

10 files changed

+385
-12
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# This workflow will run all tests in endtoend/tests in a docker container using the latest consumption image
2+
3+
name: CI Docker Consumption tests
4+
5+
on:
6+
workflow_dispatch:
7+
schedule:
8+
# Monday to Thursday 1 AM PDT build
9+
# * is a special character in YAML so you have to quote this string
10+
- cron: "0 8 * * 1,2,3,4"
11+
12+
jobs:
13+
build:
14+
name: "Python Docker CI Run"
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
20+
env:
21+
CONSUMPTION_DOCKER_TEST: "true"
22+
23+
steps:
24+
- name: Checkout code.
25+
uses: actions/checkout@v2
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple -U -e .[dev]
33+
python setup.py build
34+
python setup.py webhost --branch-name=dev
35+
python setup.py extension
36+
- name: Running 3.7 Tests
37+
if: matrix.python-version == 3.7
38+
env:
39+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString37 }}
40+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString37 }}
41+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString37 }}
42+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString37 }}
43+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString37 }}
44+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString37 }}
45+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString37 }}
46+
run: |
47+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
48+
- name: Running 3.8 Tests
49+
if: matrix.python-version == 3.8
50+
env:
51+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString38 }}
52+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString38 }}
53+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString38 }}
54+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString38 }}
55+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString38 }}
56+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString38 }}
57+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString38 }}
58+
run: |
59+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
60+
- name: Running 3.9 Tests
61+
if: matrix.python-version == 3.9
62+
env:
63+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString39 }}
64+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString39 }}
65+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString39 }}
66+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString39 }}
67+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString39 }}
68+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString39 }}
69+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString39 }}
70+
run: |
71+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
72+
- name: Running 3.10 Tests
73+
if: matrix.python-version == 3.10
74+
env:
75+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString310 }}
76+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString310 }}
77+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString310 }}
78+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString310 }}
79+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString310 }}
80+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString310 }}
81+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
82+
run: |
83+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
84+
- name: Codecov
85+
uses: codecov/[email protected]
86+
with:
87+
file: ./coverage.xml # optional
88+
flags: unittests # optional
89+
name: codecov # optional
90+
fail_ci_if_error: false # optional (default = false)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# This workflow will run all tests in endtoend/tests in a docker container using the latest dedicated image
2+
3+
4+
name: CI Docker Dedicated tests
5+
6+
on:
7+
workflow_dispatch:
8+
schedule:
9+
# Monday to Thursday 1 AM PDT build
10+
# * is a special character in YAML so you have to quote this string
11+
- cron: "0 8 * * 1,2,3,4"
12+
13+
jobs:
14+
build:
15+
name: "Python Docker CI Run"
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
21+
env:
22+
DEDICATED_DOCKER_TEST: "true"
23+
24+
steps:
25+
- name: Checkout code.
26+
uses: actions/checkout@v2
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v2
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple -U -e .[dev]
34+
python setup.py build
35+
python setup.py webhost --branch-name=dev
36+
python setup.py extension
37+
- name: Running 3.7 Tests
38+
if: matrix.python-version == 3.7
39+
env:
40+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString37 }}
41+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString37 }}
42+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString37 }}
43+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString37 }}
44+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString37 }}
45+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString37 }}
46+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString37 }}
47+
run: |
48+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
49+
- name: Running 3.8 Tests
50+
if: matrix.python-version == 3.8
51+
env:
52+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString38 }}
53+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString38 }}
54+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString38 }}
55+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString38 }}
56+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString38 }}
57+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString38 }}
58+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString38 }}
59+
run: |
60+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
61+
- name: Running 3.9 Tests
62+
if: matrix.python-version == 3.9
63+
env:
64+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString39 }}
65+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString39 }}
66+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString39 }}
67+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString39 }}
68+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString39 }}
69+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString39 }}
70+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString39 }}
71+
run: |
72+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
73+
- name: Running 3.10 Tests
74+
if: matrix.python-version == 3.10
75+
env:
76+
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString310 }}
77+
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString310 }}
78+
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString310 }}
79+
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString310 }}
80+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString310 }}
81+
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString310 }}
82+
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
83+
run: |
84+
python -m pytest -n auto --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend
85+
- name: Codecov
86+
uses: codecov/[email protected]
87+
with:
88+
file: ./coverage.xml # optional
89+
flags: unittests # optional
90+
name: codecov # optional
91+
fail_ci_if_error: false # optional (default = false)

azure_functions_worker/constants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
SHARED_MEMORY_DATA_TRANSFER = "SharedMemoryDataTransfer"
1313
FUNCTION_DATA_CACHE = "FunctionDataCache"
1414

15-
# Debug Flags
16-
PYAZURE_WEBHOST_DEBUG = "PYAZURE_WEBHOST_DEBUG"
17-
1815
# Platform Environment Variables
1916
AZURE_WEBJOBS_SCRIPT_ROOT = "AzureWebJobsScriptRoot"
2017
CONTAINER_NAME = "CONTAINER_NAME"

tests/endtoend/dependency_isolation_functions/report_dependencies/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"scriptFile": "__init__.py",
33
"bindings": [
44
{
5-
"authLevel": "function",
5+
"authLevel": "anonymous",
66
"type": "httpTrigger",
77
"direction": "in",
88
"name": "req",

tests/endtoend/http_functions/default_template/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"scriptFile": "__init__.py",
33
"bindings": [
44
{
5-
"authLevel": "function",
5+
"authLevel": "anonymous",
66
"type": "httpTrigger",
77
"direction": "in",
88
"name": "req",

tests/endtoend/sql_functions/sql_input/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"scriptFile": "__init__.py",
33
"bindings": [
44
{
5-
"authLevel": "function",
5+
"authLevel": "anonymous",
66
"name": "req",
77
"type": "httpTrigger",
88
"direction": "in",

tests/endtoend/sql_functions/sql_output/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"scriptFile": "__init__.py",
33
"bindings": [
44
{
5-
"authLevel": "function",
5+
"authLevel": "anonymous",
66
"name": "req",
77
"type": "httpTrigger",
88
"direction": "in",

tests/utils/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
# PROJECT_ROOT refers to the path to azure-functions-python-worker
66
# TODO: Find root folder without .parent
77
PROJECT_ROOT = pathlib.Path(__file__).parent.parent.parent
8+
TESTS_ROOT = PROJECT_ROOT / 'tests'
9+
WORKER_CONFIG = PROJECT_ROOT / '.testconfig'
810

911
# E2E Integration Flags and Configurations
1012
PYAZURE_INTEGRATION_TEST = "PYAZURE_INTEGRATION_TEST"
1113
PYAZURE_WORKER_DIR = "PYAZURE_WORKER_DIR"
14+
15+
# Debug Flags
16+
PYAZURE_WEBHOST_DEBUG = "PYAZURE_WEBHOST_DEBUG"
17+
18+
# CI test constants
19+
CONSUMPTION_DOCKER_TEST = "false"
20+
DEDICATED_DOCKER_TEST = "false"

tests/utils/testutils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@
4242
from azure_functions_worker.bindings.shared_memory_data_transfer \
4343
import SharedMemoryConstants as consts
4444
from azure_functions_worker.constants import (
45-
PYAZURE_WEBHOST_DEBUG,
4645
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED,
4746
UNIX_SHARED_MEMORY_DIRECTORIES
4847
)
4948
from azure_functions_worker.utils.common import is_envvar_true, get_app_setting
5049
from tests.utils.constants import PYAZURE_WORKER_DIR, \
51-
PYAZURE_INTEGRATION_TEST, PROJECT_ROOT
50+
PYAZURE_INTEGRATION_TEST, PROJECT_ROOT, WORKER_CONFIG, \
51+
CONSUMPTION_DOCKER_TEST, DEDICATED_DOCKER_TEST, PYAZURE_WEBHOST_DEBUG
52+
from tests.utils.testutils_docker import WebHostConsumption
5253

5354
TESTS_ROOT = PROJECT_ROOT / 'tests'
5455
E2E_TESTS_FOLDER = pathlib.Path('endtoend')
@@ -62,7 +63,6 @@
6263
EXTENSIONS_PATH = PROJECT_ROOT / 'build' / 'extensions' / 'bin'
6364
FUNCS_PATH = TESTS_ROOT / UNIT_TESTS_FOLDER / 'http_functions'
6465
WORKER_PATH = PROJECT_ROOT / 'python' / 'test'
65-
WORKER_CONFIG = PROJECT_ROOT / '.testconfig'
6666
ON_WINDOWS = platform.system() == 'Windows'
6767
LOCALHOST = "127.0.0.1"
6868

@@ -221,8 +221,13 @@ def setUpClass(cls):
221221

222222
_setup_func_app(TESTS_ROOT / script_dir)
223223
try:
224-
cls.webhost = start_webhost(script_dir=script_dir,
225-
stdout=cls.host_stdout)
224+
if is_envvar_true(CONSUMPTION_DOCKER_TEST):
225+
cls.webhost = WebHostConsumption(script_dir).spawn_container()
226+
elif is_envvar_true(DEDICATED_DOCKER_TEST):
227+
cls.webhost = WebHostConsumption(script_dir).spawn_container()
228+
else:
229+
cls.webhost = start_webhost(script_dir=script_dir,
230+
stdout=cls.host_stdout)
226231
except Exception:
227232
_teardown_func_app(TESTS_ROOT / script_dir)
228233
raise
@@ -917,6 +922,7 @@ def start_webhost(*, script_dir=None, stdout=None):
917922
stdout = subprocess.DEVNULL
918923

919924
port = _find_open_port()
925+
920926
proc = popen_webhost(stdout=stdout, stderr=subprocess.STDOUT,
921927
script_root=script_root, port=port)
922928
time.sleep(10) # Giving host some time to start fully.

0 commit comments

Comments
 (0)