fix: resolve issue where explicit routing metadata was not sent in async clients#2133
fix: resolve issue where explicit routing metadata was not sent in async clients#2133
Conversation
f3e66ba to
b9d0532
Compare
b9d0532 to
068dfe9
Compare
068dfe9 to
fd74cbc
Compare
Co-authored-by: Victor Chudnovsky <vchudnov@google.com>
vchudnov-g
left a comment
There was a problem hiding this comment.
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 %} |
There was a problem hiding this comment.
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.
| # Establish that the underlying gRPC stub method was called. | ||
| call.assert_called() | ||
| _, args, _ = call.mock_calls[0] | ||
| _, args, kw = call.mock_calls[0] |
There was a problem hiding this comment.
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?
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
|
|
||
| {% 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'] |
There was a problem hiding this comment.
Is this code path tested? I don't find it in any of the goldens.
There was a problem hiding this comment.
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 %} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
This PR depends on #2126 and #2131. Please review those PRs first.
See https://google.aip.dev/client-libraries/4222
test_*_routing_parametersso that it can be used for both sync and async test casesFixes #2091