Skip to content

Conversation

@parthea
Copy link
Contributor

@parthea parthea commented Sep 9, 2024

This PR depends on #2126 and #2131. Please review those PRs first.

See https://google.aip.dev/client-libraries/4222

  • Refactor test_*_routing_parameters so that it can be used for both sync and async test cases

Fixes #2091

@product-auto-label product-auto-label bot added size: m Pull request size is medium. size: l Pull request size is large. and removed size: m Pull request size is medium. labels Sep 9, 2024
@parthea parthea force-pushed the refactor-routing-parameters-test branch from f3e66ba to b9d0532 Compare September 9, 2024 12:46
@parthea parthea changed the title chore: refactor routing_parameters test fix: resolve issue where explicit routing was not supported in async clients Sep 9, 2024
@parthea parthea changed the title fix: resolve issue where explicit routing was not supported in async clients fix: resolve issue where explicit routing metadata was not sent in async clients Sep 9, 2024
@parthea parthea marked this pull request as ready for review September 9, 2024 12:50
@parthea parthea requested a review from a team as a code owner September 9, 2024 12:50
@parthea parthea force-pushed the refactor-routing-parameters-test branch from b9d0532 to 068dfe9 Compare September 9, 2024 13:16
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Sep 9, 2024
@parthea parthea force-pushed the refactor-routing-parameters-test branch from 068dfe9 to fd74cbc Compare September 9, 2024 14:42
Co-authored-by: Victor Chudnovsky <[email protected]>
Base automatically changed from refactor-empty-call-test to main September 14, 2024 12:08
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: xl Pull request size is extra large. labels Sep 15, 2024
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Sep 15, 2024
@parthea parthea changed the base branch from main to fix-routing-parameter-assert September 15, 2024 14:18
Copy link
Contributor

@vchudnov-g vchudnov-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good, but I want to have look after this is rebased on HEAD.

metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((
{% for field_header in method.field_headers %}
{% if not method.client_streaming %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I know this PR just moved the pre-existing code into this macro, but we could move the {% if %} outside the {% for %} since method is not altered by the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3da4cc9

Base automatically changed from fix-routing-parameter-assert to main September 16, 2024 21:46
# Establish that the underlying gRPC stub method was called.
call.assert_called()
_, args, _ = call.mock_calls[0]
_, args, kw = call.mock_calls[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the kw should be wrapped in {% if routing_param %} because otherwise it won't be used in the generated code. This could lead to linter warnings, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5fa4a39


{% if routing_param %}
expected_headers = {{ method.routing_rule.resolve(method.routing_rule, routing_param.sample_request) }}
assert gapic_v1.routing_header.to_grpc_metadata(expected_headers) in kw['metadata']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code path tested? I don't find it in any of the goldens.

Copy link
Contributor Author

@parthea parthea Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can add an assert False when running the showcase unit tests and tests will fail. I attempted to add golden files for showcase in #1991 but ran into the issue in #1993

To test locally make the following change and run nox -s showcase_unit-3.9

(py392) partheniou@partheniou-vm-3:~/git/gapic-generator-python$ git diff
diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
index f3c20ea5..e9cb6c0c 100644
--- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
+++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
@@ -1843,6 +1843,7 @@ def test_{{ method_name }}_rest_no_http_options():
         {% if routing_param %}
         expected_headers = {{ method.routing_rule.resolve(method.routing_rule, routing_param.sample_request) }}
         assert gapic_v1.routing_header.to_grpc_metadata(expected_headers) in kw['metadata']
+        assert False
         {% endif %}
 {% endwith %}{# method_name #}
 {% endmacro %}
(py392) partheniou@partheniou-vm-3:~/git/gapic-generator-python$ nox -s showcase_unit-3.9
nox > Running session showcase_unit-3.9
nox > Creating virtual environment (virtualenv) using python3.9 in .nox/showcase_unit-3-9
...
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_7_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_2_grpc_asyncio - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_1_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_8_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_3_grpc_asyncio - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_2_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_4_grpc_asyncio - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_3_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_1_grpc_asyncio - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_5_grpc_asyncio - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_4_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_6_grpc_asyncio - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_5_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_7_grpc_asyncio - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_6_grpc - assert False
FAILED tests/unit/gapic/showcase_v1beta1/test_echo.py::test_echo_routing_parameters_request_8_grpc_asyncio - assert False
16 failed, 1134 passed, 10 skipped, 58 warnings in 17.76s

{% endmacro %}

{% macro create_metadata(method) %}
{% if method.explicit_routing %}
Copy link
Contributor

@daniel-sanche daniel-sanche Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To resolve #2078, we'll probably need to add an extra check here for passed-in routing metadata:

metadata = tuple(metadata)
# add routing headers if not passed in metadata
if not any (m[0] == gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata):
   {% if method.explicit_routing %}
   ...

I have #2079 open to try to address this, and I plan to fix it up to match this new structure after this PR is merged. But I'm mentioning it now in case you think it makes more sense to just address these together here

Copy link
Contributor Author

@parthea parthea Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #2078 we need to update AIPs first so there is consistent behavior across all language-specific generators: https://google.aip.dev/client-libraries/4222

I'm going to go ahead without #2078 as there is still work pending

parthea and others added 2 commits September 18, 2024 10:40
Co-authored-by: Victor Chudnovsky <[email protected]>
@parthea parthea merged commit c222b12 into main Sep 18, 2024
@parthea parthea deleted the refactor-routing-parameters-test branch September 18, 2024 16:21
@parthea parthea restored the refactor-routing-parameters-test branch October 9, 2024 16:31
@parthea parthea deleted the refactor-routing-parameters-test branch October 9, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

async client does not support explicit routing

4 participants