Skip to content

Commit 72100cb

Browse files
committed
tests: add test_recv_results_prepared_v5_reads_metadata_id
Both existing recv_results_prepared tests used protocol_version=4, leaving the ProtocolVersion.uses_prepared_metadata() branch (v5+) untested. The new test confirms that on protocol v5, result_metadata_id is read from the PREPARE response even when use_metadata_id=False (native v5 path).
1 parent c04e07c commit 72100cb

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

tests/unit/test_protocol.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,33 @@ def test_recv_results_prepared_no_extension_skips_metadata_id(self):
191191
assert msg.query_id == b'ab'
192192
assert msg.result_metadata_id is None
193193

194-
def test_recv_results_metadata_changed_flag(self):
194+
def test_recv_results_prepared_v5_reads_metadata_id(self):
195+
"""
196+
On protocol v5, ProtocolVersion.uses_prepared_metadata() is True, so
197+
result_metadata_id must be read from the PREPARE response even when
198+
use_metadata_id is False (native v5 path, not the Scylla extension).
199+
"""
200+
buf = io.BytesIO(
201+
struct.pack('>H', 2) + b'ab' # query_id
202+
+ struct.pack('>H', 3) + b'xyz' # result_metadata_id (always present on v5)
203+
+ struct.pack('>i', 1) # prepared flags: global_tables_spec
204+
+ struct.pack('>i', 0) # colcount = 0
205+
+ struct.pack('>i', 0) # num_pk_indexes = 0
206+
+ struct.pack('>H', 2) + b'ks' # ksname
207+
+ struct.pack('>H', 2) + b'tb' # cfname
208+
+ struct.pack('>i', 4) # result flags: no_metadata
209+
+ struct.pack('>i', 0) # result colcount = 0
210+
)
211+
212+
features_no_extension = ProtocolFeatures(use_metadata_id=False)
213+
msg = ResultMessage(kind=4) # RESULT_KIND_PREPARED = 4
214+
msg.recv_results_prepared(buf, protocol_version=5,
215+
protocol_features=features_no_extension,
216+
user_type_map={})
217+
assert msg.query_id == b'ab'
218+
assert msg.result_metadata_id == b'xyz'
219+
220+
195221
"""
196222
When _METADATA_ID_FLAG (0x0008) is set in a ROWS result,
197223
recv_results_metadata must read and store the new result_metadata_id

0 commit comments

Comments
 (0)