From fe52ed2a8296ad354f22f3d74a817c23f8bb341c Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Wed, 16 Dec 2020 13:55:39 -0800 Subject: [PATCH] xds_testing: add more header matcher tests - present_match - Int64Range range_match --- tools/run_tests/run_xds_tests.py | 55 +++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/tools/run_tests/run_xds_tests.py b/tools/run_tests/run_xds_tests.py index 9ffcb261342..b4927b987b0 100755 --- a/tools/run_tests/run_xds_tests.py +++ b/tools/run_tests/run_xds_tests.py @@ -285,6 +285,9 @@ _TESTS_TO_SEND_METADATA = ['header_matching'] _TEST_METADATA_KEY = 'xds_md' _TEST_METADATA_VALUE_UNARY = 'unary_yranu' _TEST_METADATA_VALUE_EMPTY = 'empty_ytpme' +# Extra RPC metadata whose value is a number, sent with UnaryCall only. +_TEST_METADATA_NUMERIC_KEY = 'xds_md_numeric' +_TEST_METADATA_NUMERIC_VALUE = '159' _PATH_MATCHER_NAME = 'path-matcher' _BASE_TEMPLATE_NAME = 'test-template' _BASE_INSTANCE_GROUP_NAME = 'test-ig' @@ -1158,22 +1161,64 @@ def test_header_matching(gcp, original_backend_service, instance_group, "EmptyCall": alternate_backend_instances, "UnaryCall": original_backend_instances }), + ( + [{ + 'priority': 0, + # Header 'xds_md_numeric' present -> alternate_backend_service. + # UnaryCall is sent with the metadata, so will be sent to alternative. + 'matchRules': [{ + 'prefixMatch': + '/', + 'headerMatches': [{ + 'headerName': _TEST_METADATA_NUMERIC_KEY, + 'presentMatch': True + }] + }], + 'service': alternate_backend_service.url + }], + { + "EmptyCall": original_backend_instances, + "UnaryCall": alternate_backend_instances + }), ( [{ 'priority': 0, # Header invert ExactMatch -> alternate_backend_service. - # EmptyCall is sent with the metadata, so will be sent to original. + # UnaryCall is sent with the metadata, so will be sent to + # original. EmptyCall will be sent to alternative. 'matchRules': [{ 'prefixMatch': '/', 'headerMatches': [{ 'headerName': _TEST_METADATA_KEY, - 'exactMatch': _TEST_METADATA_VALUE_EMPTY, + 'exactMatch': _TEST_METADATA_VALUE_UNARY, 'invertMatch': True }] }], 'service': alternate_backend_service.url }], + { + "EmptyCall": alternate_backend_instances, + "UnaryCall": original_backend_instances + }), + ( + [{ + 'priority': 0, + # Header 'xds_md_numeric' range [100,200] -> alternate_backend_service. + # UnaryCall is sent with the metadata in range. + 'matchRules': [{ + 'prefixMatch': + '/', + 'headerMatches': [{ + 'headerName': _TEST_METADATA_NUMERIC_KEY, + 'rangeMatch': { + 'rangeStart': '100', + 'rangeEnd': '200' + } + }] + }], + 'service': alternate_backend_service.url + }], { "EmptyCall": original_backend_instances, "UnaryCall": alternate_backend_instances @@ -2214,11 +2259,13 @@ try: rpcs_to_send = '--rpc="UnaryCall"' if test_case in _TESTS_TO_SEND_METADATA: - metadata_to_send = '--metadata="EmptyCall:{keyE}:{valueE},UnaryCall:{keyU}:{valueU}"'.format( + metadata_to_send = '--metadata="EmptyCall:{keyE}:{valueE},UnaryCall:{keyU}:{valueU},UnaryCall:{keyNU}:{valueNU}"'.format( keyE=_TEST_METADATA_KEY, valueE=_TEST_METADATA_VALUE_EMPTY, keyU=_TEST_METADATA_KEY, - valueU=_TEST_METADATA_VALUE_UNARY) + valueU=_TEST_METADATA_VALUE_UNARY, + keyNU=_TEST_METADATA_NUMERIC_KEY, + valueNU=_TEST_METADATA_NUMERIC_VALUE) else: # Setting the arg explicitly to empty with '--metadata=""' # makes C# client fail