|
14 | 14 |
|
15 | 15 | import pytest |
16 | 16 | from grpc import RpcError |
| 17 | +from grpc import ClientCallDetails |
17 | 18 |
|
18 | 19 | from google.cloud.bigtable.data._metrics.data_model import OperationState |
19 | 20 | from google.cloud.bigtable.data._cross_sync import CrossSync |
@@ -128,6 +129,28 @@ def test_on_operation_cancelled(self): |
128 | 129 | op.cancel() |
129 | 130 | assert op.uuid not in instance.operation_map |
130 | 131 |
|
| 132 | + @CrossSync.pytest |
| 133 | + async def test_strip_operation_id_metadata(self): |
| 134 | + """ |
| 135 | + After operation id is detected in metadata, the field should be stripped out before calling continuation |
| 136 | + """ |
| 137 | + from google.cloud.bigtable.data._metrics.data_model import ( |
| 138 | + OPERATION_INTERCEPTOR_METADATA_KEY, |
| 139 | + ) |
| 140 | + |
| 141 | + instance = self._make_one() |
| 142 | + op = mock.Mock() |
| 143 | + op.uuid = "test-uuid" |
| 144 | + op.state = OperationState.ACTIVE_ATTEMPT |
| 145 | + instance.operation_map[op.uuid] = op |
| 146 | + continuation = CrossSync.Mock() |
| 147 | + details = ClientCallDetails() |
| 148 | + details.metadata = [(OPERATION_INTERCEPTOR_METADATA_KEY, op.uuid), ("other_key", "other_value")] |
| 149 | + await instance.intercept_unary_unary(continuation, details, mock.Mock()) |
| 150 | + assert details.metadata == [("other_key", "other_value")] |
| 151 | + assert continuation.call_count == 1 |
| 152 | + assert continuation.call_args[0][0].metadata == [("other_key", "other_value")] |
| 153 | + |
131 | 154 | @CrossSync.pytest |
132 | 155 | async def test_unary_unary_interceptor_op_not_found(self): |
133 | 156 | """Test that interceptor call cuntinuation if op is not found""" |
|
0 commit comments