Skip to content

Enable support for handling new command line arguments #1318

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

Merged
merged 4 commits into from
Sep 20, 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
13 changes: 12 additions & 1 deletion azure_functions_worker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the MIT License.
"""Main entrypoint."""


import argparse


Expand All @@ -26,6 +25,18 @@ def parse_args():
'syslog, or a file path')
parser.add_argument('--grpcMaxMessageLength', type=int,
dest='grpc_max_msg_len')
parser.add_argument('--functions-uri', dest='functions_uri', type=str,
help='URI with IP Address and Port used to'
' connect to the Host via gRPC.')
parser.add_argument('--functions-request-id', dest='functions_request_id',
type=str, help='Request ID used for gRPC communication '
'with the Host.')
parser.add_argument('--functions-worker-id',
dest='functions_worker_id', type=str,
help='Worker ID assigned to this language worker.')
parser.add_argument('--functions-grpc-max-message-length', type=int,
dest='functions_grpc_max_msg_len',
help='Max grpc message length for Functions')
return parser.parse_args()


Expand Down
79 changes: 79 additions & 0 deletions tests/unittests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import unittest
import sys
from unittest.mock import patch
from azure_functions_worker.main import parse_args


class TestMain(unittest.TestCase):

@patch.object(sys, 'argv',
['xxx', '--host', '127.0.0.1',
'--port', '50821',
'--workerId', 'e9efd817-47a1-45dc-9e20-e6f975d7a025',
'--requestId', 'cbef5957-cdb3-4462-9ee7-ac9f91be0a51',
'--grpcMaxMessageLength', '2147483647',
'--functions-uri', 'http://127.0.0.1:50821',
'--functions-worker-id',
'e9efd817-47a1-45dc-9e20-e6f975d7a025',
'--functions-request-id',
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51',
'--functions-grpc-max-message-length', '2147483647'])
def test_all_args(self):
args = parse_args()
self.assertEqual(args.host, '127.0.0.1')
self.assertEqual(args.port, 50821)
self.assertEqual(args.worker_id,
'e9efd817-47a1-45dc-9e20-e6f975d7a025')
self.assertEqual(args.request_id,
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51')
self.assertEqual(args.grpc_max_msg_len, 2147483647)
self.assertEqual(args.functions_uri, 'http://127.0.0.1:50821')
self.assertEqual(args.functions_worker_id,
'e9efd817-47a1-45dc-9e20-e6f975d7a025')
self.assertEqual(args.functions_request_id,
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51')
self.assertEqual(args.functions_grpc_max_msg_len, 2147483647)

@patch.object(sys, 'argv',
['xxx', '--host', '127.0.0.1',
'--port', '50821',
'--workerId', 'e9efd817-47a1-45dc-9e20-e6f975d7a025',
'--requestId', 'cbef5957-cdb3-4462-9ee7-ac9f91be0a51',
'--grpcMaxMessageLength', '2147483647'])
def test_old_args(self):
args = parse_args()
self.assertEqual(args.host, '127.0.0.1')
self.assertEqual(args.port, 50821)
self.assertEqual(args.worker_id,
'e9efd817-47a1-45dc-9e20-e6f975d7a025')
self.assertEqual(args.request_id,
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51')
self.assertEqual(args.grpc_max_msg_len, 2147483647)
self.assertIsNone(args.functions_uri)
self.assertIsNone(args.functions_worker_id)
self.assertIsNone(args.functions_request_id)
self.assertIsNone(args.functions_grpc_max_msg_len)

@patch.object(sys, 'argv',
['xxx', '--functions-uri', 'http://127.0.0.1:50821',
'--functions-worker-id',
'e9efd817-47a1-45dc-9e20-e6f975d7a025',
'--functions-request-id',
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51',
'--functions-grpc-max-message-length', '2147483647'])
def test_new_args(self):
args = parse_args()
self.assertEqual(args.functions_uri, 'http://127.0.0.1:50821')
self.assertEqual(args.functions_worker_id,
'e9efd817-47a1-45dc-9e20-e6f975d7a025')
self.assertEqual(args.functions_request_id,
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51')
self.assertEqual(args.functions_grpc_max_msg_len, 2147483647)

@patch.object(sys, 'argv', ['xxx', '--host', 'dummy_host',
'--port', '12345',
'--invalid-arg', 'invalid_value'])
def test_invalid_args(self):
with self.assertRaises(SystemExit) as context:
parse_args()
self.assertEqual(context.exception.code, 2)