Skip to content

Commit 170fd31

Browse files
committed
DRIVER-153: tests for ExecuteMessage use_metadata_id flag and sentinel behaviour
- test_execute_message_scylla_metadata_id_v4: require use_metadata_id=True to reflect the new API (field is gated on the flag, not on non-None value) - test_execute_message_scylla_metadata_id_none_writes_sentinel: new test — extension active but result_metadata_id=None writes empty sentinel b'' (\x00\x00 + b'') keeping the frame layout correct for LWT / mixed-cluster - test_response_future skip_meta tests: assert message.use_metadata_id to cover all four cases (extension on/off, metadata id present/absent, LWT, protocol v5)
1 parent 923819e commit 170fd31

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

tests/unit/test_protocol.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ def test_execute_message_skip_meta_flag(self):
8383
self._check_calls(mock_io, [(b'\x00\x01',), (b'1',), (b'\x00\x04',), (b'\x03',), (b'\x00\x00',)])
8484

8585
def test_execute_message_scylla_metadata_id_v4(self):
86-
"""result_metadata_id should be written on protocol v4 when set (Scylla extension)."""
86+
"""result_metadata_id should be written on protocol v4 when use_metadata_id=True (Scylla extension)."""
8787
message = ExecuteMessage('1', [], 4)
8888
message.result_metadata_id = b'foo'
89+
message.use_metadata_id = True
8990
mock_io = Mock()
9091

9192
message.send_body(mock_io, 4)
@@ -94,6 +95,23 @@ def test_execute_message_scylla_metadata_id_v4(self):
9495
(b'\x00\x03',), (b'foo',),
9596
(b'\x00\x04',), (b'\x01',), (b'\x00\x00',)])
9697

98+
def test_execute_message_scylla_metadata_id_none_writes_sentinel(self):
99+
"""
100+
When use_metadata_id=True but result_metadata_id is None (e.g. LWT statement or
101+
mixed cluster), send_body must still write the field as an empty string sentinel
102+
(\\x00\\x00) so the frame layout matches what the server expects.
103+
"""
104+
message = ExecuteMessage('1', [], 4)
105+
message.use_metadata_id = True
106+
# result_metadata_id intentionally left as None
107+
mock_io = Mock()
108+
109+
message.send_body(mock_io, 4)
110+
# empty sentinel: \x00\x00 (zero-length short) + b'' (zero bytes), then normal query params
111+
self._check_calls(mock_io, [(b'\x00\x01',), (b'1',),
112+
(b'\x00\x00',), (b'',),
113+
(b'\x00\x04',), (b'\x01',), (b'\x00\x00',)])
114+
97115
def test_recv_results_prepared_scylla_extension_reads_metadata_id(self):
98116
"""
99117
When use_metadata_id is True (Scylla extension), result_metadata_id must be

tests/unit/test_response_future.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,7 @@ def test_query_sets_skip_meta_with_scylla_extension(self):
904904

905905
assert rf.message.skip_meta is True
906906
assert rf.message.result_metadata_id == b'meta_hash'
907-
908-
def test_query_no_skip_meta_without_extension(self):
907+
assert rf.message.use_metadata_id is True
909908
"""
910909
When the connection does NOT have SCYLLA_USE_METADATA_ID (and protocol
911910
is v4), _query() must leave skip_meta=False and result_metadata_id=None.
@@ -929,6 +928,7 @@ def test_query_no_skip_meta_without_extension(self):
929928

930929
assert rf.message.skip_meta is False
931930
assert rf.message.result_metadata_id is None
931+
assert rf.message.use_metadata_id is False
932932

933933
def test_query_no_skip_meta_when_prepared_statement_has_no_metadata_id(self):
934934
"""
@@ -955,6 +955,7 @@ def test_query_no_skip_meta_when_prepared_statement_has_no_metadata_id(self):
955955

956956
assert rf.message.skip_meta is False
957957
assert rf.message.result_metadata_id is None
958+
assert rf.message.use_metadata_id is True # extension active — field must still appear on wire
958959

959960
def test_query_sets_skip_meta_for_protocol_v5(self):
960961
"""
@@ -981,6 +982,7 @@ def test_query_sets_skip_meta_for_protocol_v5(self):
981982

982983
assert rf.message.skip_meta is True
983984
assert rf.message.result_metadata_id == b'v5_hash'
985+
assert rf.message.use_metadata_id is False # v5 native path; Scylla extension not active
984986

985987
def test_query_no_skip_meta_when_result_metadata_is_none(self):
986988
"""
@@ -1015,3 +1017,4 @@ def test_query_no_skip_meta_when_result_metadata_is_none(self):
10151017

10161018
assert rf.message.skip_meta is False
10171019
assert rf.message.result_metadata_id is None
1020+
assert rf.message.use_metadata_id is True # extension active — sentinel b'' will be written

0 commit comments

Comments
 (0)