Skip to content

Commit 2e91fa1

Browse files
authored
Fixed unit and docker tests (#1438)
* fixed invalid stein tests * removed retries * @pytest.mark.asyncio * pytest-asyncio in setup.py * class scope * event loop policy * def event_loop * check status * fixing filename docker tests * fixing dispatcher tests
1 parent 7de7724 commit 2e91fa1

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
lines changed

.github/workflows/ci_docker_con_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
19+
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]
2020
permissions: read-all
2121
env:
2222
CONSUMPTION_DOCKER_TEST: "true"

tests/endtoend/test_file_name_functions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ class TestHttpFunctionsFileName(testutils.WebHostTestCase):
2424
@classmethod
2525
def setUpClass(cls):
2626
os.environ["PYTHON_SCRIPT_FILE_NAME"] = "main.py"
27+
cls.env_variables['PYTHON_SCRIPT_FILE_NAME'] = 'main.py'
2728
super().setUpClass()
2829

2930
@classmethod
3031
def tearDownClass(cls):
31-
# Remove the WEBSITE_HOSTNAME environment variable
32+
# Remove the PYTHON_SCRIPT_FILE_NAME environment variable
3233
os.environ.pop('PYTHON_SCRIPT_FILE_NAME')
3334
super().tearDownClass()
3435

@@ -38,6 +39,10 @@ def get_script_dir(cls):
3839
'http_functions_stein' / \
3940
'file_name'
4041

42+
@classmethod
43+
def get_environment_variables(cls):
44+
return cls.env_variables
45+
4146
@testutils.retryable_test(3, 5)
4247
def test_index_page_should_return_ok(self):
4348
"""The index page of Azure Functions should return OK in any

tests/unittests/test_dispatcher.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ async def test_dispatcher_sync_threadpool_default_worker(self):
143143
correct default value
144144
"""
145145
async with self._ctrl as host:
146-
# await self._check_if_function_is_ok(host)
146+
await host.init_worker()
147+
await self._check_if_function_is_ok(host)
147148
await self._assert_workers_threadpool(self._ctrl, host,
148149
self._default_workers)
149150

@@ -154,6 +155,7 @@ async def test_dispatcher_sync_threadpool_set_worker(self):
154155
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT:
155156
f'{self._allowed_max_workers}'})
156157
async with self._ctrl as host:
158+
await host.init_worker()
157159
await self._check_if_function_is_ok(host)
158160
await self._assert_workers_threadpool(self._ctrl, host,
159161
self._allowed_max_workers)
@@ -335,10 +337,11 @@ async def test_async_invocation_request_log(self):
335337
)
336338

337339
async def test_sync_invocation_request_log_threads(self):
338-
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '5'})
339-
340340
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
341+
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '5'})
342+
341343
async with self._ctrl as host:
344+
await host.init_worker()
342345
request_id: str = self._ctrl._worker._request_id
343346
func_id, invoke_id, func_name = (
344347
await self._check_if_function_is_ok(host)
@@ -359,10 +362,11 @@ async def test_sync_invocation_request_log_threads(self):
359362
)
360363

361364
async def test_async_invocation_request_log_threads(self):
362-
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '4'})
363-
364365
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
366+
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '4'})
367+
365368
async with self._ctrl as host:
369+
await host.init_worker()
366370
request_id: str = self._ctrl._worker._request_id
367371
func_id, invoke_id, func_name = (
368372
await self._check_if_async_function_is_ok(host)

tests/unittests/test_enable_debug_logging_functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def setUpClass(cls):
3535

3636
@classmethod
3737
def tearDownClass(cls):
38+
os.environ.pop(PYTHON_ENABLE_DEBUG_LOGGING)
3839
super().tearDownClass()
3940
cls._patch_environ.stop()
4041

@@ -72,6 +73,7 @@ def setUpClass(cls):
7273

7374
@classmethod
7475
def tearDownClass(cls):
76+
os.environ.pop(PYTHON_ENABLE_DEBUG_LOGGING)
7577
super().tearDownClass()
7678
cls._patch_environ.stop()
7779

@@ -118,6 +120,7 @@ def tearDownClass(cls):
118120
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json'
119121
remove_path(host_json)
120122

123+
os.environ.pop(PYTHON_ENABLE_DEBUG_LOGGING)
121124
super().tearDownClass()
122125
cls._patch_environ.stop()
123126

tests/unittests/test_invalid_stein.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
import collections as col
4-
53
from azure_functions_worker import protos
64
from tests.utils import testutils
75

8-
SysVersionInfo = col.namedtuple("VersionInfo", ["major", "minor", "micro",
9-
"releaselevel", "serial"])
106
STEIN_INVALID_APP_FUNCTIONS_DIR = testutils.UNIT_TESTS_FOLDER / \
117
'broken_functions' / \
128
'invalid_app_stein'
@@ -17,24 +13,30 @@
1713

1814
class TestInvalidAppStein(testutils.AsyncTestCase):
1915

16+
@testutils.retryable_test(4, 5)
2017
async def test_indexing_not_app(self):
21-
"""Test if the functions metadata response will be 0
22-
when an invalid app is provided
23-
"""
24-
mock_host = testutils.start_mockhost(
25-
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
26-
async with mock_host as host:
18+
"""Test if the functions metadata status will be
19+
Failure when an invalid app is provided
20+
"""
21+
async with testutils.start_mockhost(
22+
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR) as host:
23+
await host.init_worker()
2724
r = await host.get_functions_metadata()
2825
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
29-
self.assertIn("Error", r.response.result.exception.message)
26+
self.assertEqual(r.response.result.status,
27+
protos.StatusResult.Failure)
28+
self.assertIsNotNone(r.response.result.exception.message)
3029

30+
@testutils.retryable_test(4, 5)
3131
async def test_indexing_invalid_app(self):
32-
"""Test if the functions metadata response will be 0
33-
when an invalid app is provided
34-
"""
35-
mock_host = testutils.start_mockhost(
36-
script_root=STEIN_INVALID_APP_FUNCTIONS_DIR)
37-
async with mock_host as host:
32+
"""Test if the functions metadata status will be
33+
Failure when an invalid app is provided
34+
"""
35+
async with testutils.start_mockhost(
36+
script_root=STEIN_INVALID_FUNCTIONS_DIR) as host:
37+
await host.init_worker()
3838
r = await host.get_functions_metadata()
3939
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
40-
self.assertIn("Error", r.response.result.exception.message)
40+
self.assertEqual(r.response.result.status,
41+
protos.StatusResult.Failure)
42+
self.assertIsNotNone(r.response.result.exception.message)

0 commit comments

Comments
 (0)