Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding missing inits in tests to correct binding load errors #1354

Merged
merged 1 commit into from
Nov 14, 2023
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
20 changes: 16 additions & 4 deletions tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ async def test_dispatcher_environment_reload_logging(self):
mode (Linux Consumption)
"""
async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)

# Reload environment variable on specialization
Expand Down Expand Up @@ -155,6 +156,7 @@ async def test_dispatcher_sync_threadpool_invalid_worker_count(self):
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: 'invalid'})

async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)
await self._assert_workers_threadpool(self._ctrl, host,
self._default_workers)
Expand All @@ -169,6 +171,7 @@ async def test_dispatcher_sync_threadpool_below_min_setting(self):
# Configure thread pool max worker to an invalid value
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '0'})
async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)
await self._assert_workers_threadpool(self._ctrl, host,
self._default_workers)
Expand All @@ -187,6 +190,7 @@ async def test_dispatcher_sync_threadpool_exceed_max_setting(self):
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT:
f'{self._over_max_workers}'})
async with self._ctrl as host:
await host.init_worker('4.15.1')
await self._check_if_function_is_ok(host)

# Ensure the dispatcher sync threadpool should fallback to max
Expand All @@ -198,6 +202,7 @@ async def test_dispatcher_sync_threadpool_in_placeholder(self):
mode (Linux Consumption)
"""
async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)

# Reload environment variable on specialization
Expand All @@ -213,6 +218,7 @@ async def test_dispatcher_sync_threadpool_in_placeholder_invalid(self):
"""
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)

# Reload environment variable on specialization
Expand All @@ -234,6 +240,7 @@ async def test_dispatcher_sync_threadpool_in_placeholder_above_max(self):
"""
with patch('azure_functions_worker.dispatcher.logger'):
async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)

# Reload environment variable on specialization
Expand All @@ -249,6 +256,7 @@ async def test_dispatcher_sync_threadpool_in_placeholder_below_min(self):
"""
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
async with self._ctrl as host:
await host.init_worker()
await self._check_if_function_is_ok(host)

# Reload environment variable on specialization
Expand All @@ -268,6 +276,7 @@ async def test_dispatcher_sync_threadpool_in_placeholder_below_min(self):
async def test_sync_invocation_request_log(self):
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
async with self._ctrl as host:
await host.init_worker()
request_id: str = self._ctrl._worker._request_id
func_id, invoke_id, func_name = (
await self._check_if_function_is_ok(host)
Expand All @@ -286,6 +295,7 @@ async def test_sync_invocation_request_log(self):
async def test_async_invocation_request_log(self):
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
async with self._ctrl as host:
await host.init_worker()
request_id: str = self._ctrl._worker._request_id
func_id, invoke_id, func_name = (
await self._check_if_async_function_is_ok(host)
Expand Down Expand Up @@ -543,6 +553,7 @@ async def test_dispatcher_functions_metadata_request(self):
when a functions metadata request is received
"""
async with self._ctrl as host:
await host.init_worker()
r = await host.get_functions_metadata()
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertFalse(r.response.use_default_metadata_indexing)
Expand All @@ -554,6 +565,7 @@ async def test_dispatcher_functions_metadata_request_with_retry(self):
when a functions metadata request is received
"""
async with self._ctrl as host:
await host.init_worker()
r = await host.get_functions_metadata()
self.assertIsInstance(r.response, protos.FunctionMetadataResponse)
self.assertFalse(r.response.use_default_metadata_indexing)
Expand Down Expand Up @@ -609,7 +621,7 @@ async def test_dispatcher_load_azfunc_in_init(self):
"""Test if azure functions is loaded during init
"""
async with self._ctrl as host:
r = await host.init_worker('4.15.1')
r = await host.init_worker()
self.assertEqual(
len([log for log in r.logs if log.message.startswith(
'Received WorkerInitRequest'
Expand All @@ -625,7 +637,7 @@ async def test_dispatcher_load_modules_dedicated_app(self):

# Dedicated Apps where placeholder mode is not set
async with self._ctrl as host:
r = await host.init_worker('4.15.1')
r = await host.init_worker()
logs = [log.message for log in r.logs]
self.assertIn(
"Applying prioritize_customer_dependencies: "
Expand All @@ -643,7 +655,7 @@ async def test_dispatcher_load_modules_con_placeholder_enabled(self):
os.environ["CONTAINER_NAME"] = "test"
os.environ["WEBSITE_PLACEHOLDER_MODE"] = "1"
async with self._ctrl as host:
r = await host.init_worker('4.15.1')
r = await host.init_worker()
logs = [log.message for log in r.logs]
self.assertNotIn(
"Applying prioritize_customer_dependencies: "
Expand All @@ -660,7 +672,7 @@ async def test_dispatcher_load_modules_con_app_placeholder_disabled(self):
os.environ["WEBSITE_PLACEHOLDER_MODE"] = "0"
os.environ["CONTAINER_NAME"] = "test"
async with self._ctrl as host:
r = await host.init_worker('4.15.1')
r = await host.init_worker()
logs = [log.message for log in r.logs]
self.assertIn(
"Applying prioritize_customer_dependencies: "
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def worker_id(self):
def request_id(self):
return self._request_id

async def init_worker(self, host_version: str):
async def init_worker(self, host_version: str = '4.28.0'):
r = await self.communicate(
protos.StreamingMessage(
worker_init_request=protos.WorkerInitRequest(
Expand Down