Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 9cbda99

Browse files
committed
added test
1 parent 2b35127 commit 9cbda99

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/unit/data/_async/test_metrics_interceptor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import pytest
1616
from grpc import RpcError
17+
from grpc import ClientCallDetails
1718

1819
from google.cloud.bigtable.data._metrics.data_model import OperationState
1920
from google.cloud.bigtable.data._cross_sync import CrossSync
@@ -128,6 +129,28 @@ def test_on_operation_cancelled(self):
128129
op.cancel()
129130
assert op.uuid not in instance.operation_map
130131

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+
131154
@CrossSync.pytest
132155
async def test_unary_unary_interceptor_op_not_found(self):
133156
"""Test that interceptor call cuntinuation if op is not found"""

0 commit comments

Comments
 (0)