Skip to content

Commit 51dbe8b

Browse files
committed
tests: add more integration tests for metadata_request_timeout
New behavior needs to be tested: 1. metadata_request_timeout can be borrowed from control_connection_timeout 2. metadata_request_timeout can be set to 0, to disable it. 3. metadata_request_timeout can be set to some value to override default. 4. When both metadata_request_timeout and control_connection_timeou it should be disabled
1 parent 42df52b commit 51dbe8b

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

tests/integration/standard/test_metadata.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import sys
2121
import time
2222
import os
23+
from typing import Optional
24+
2325
from packaging.version import Version
2426
from unittest.mock import Mock, patch
2527
import pytest
@@ -1323,20 +1325,39 @@ def test_token(self):
13231325
cluster.shutdown()
13241326

13251327

1326-
class MetadataTimeoutTest(unittest.TestCase):
1328+
class TestMetadataTimeout:
13271329
"""
13281330
Test of TokenMap creation and other behavior.
13291331
"""
1330-
def test_timeout(self):
1331-
cluster = TestCluster()
1332-
cluster.metadata_request_timeout = None
13331332

1333+
@pytest.mark.parametrize(
1334+
"opts, expected_query_chunk",
1335+
[
1336+
(
1337+
{"metadata_request_timeout": None},
1338+
# Should be borrowed from control_connection_timeout
1339+
"USING TIMEOUT 2000ms"
1340+
),
1341+
(
1342+
{"metadata_request_timeout": 0.0},
1343+
False
1344+
),
1345+
(
1346+
{"metadata_request_timeout": 4.0},
1347+
"USING TIMEOUT 4000ms"
1348+
),
1349+
(
1350+
{"metadata_request_timeout": None, "control_connection_timeout": None},
1351+
False,
1352+
)
1353+
],
1354+
ids=["default", "zero", "4s", "both none"]
1355+
)
1356+
def test_timeout(self, opts, expected_query_chunk):
1357+
cluster = TestCluster(**opts)
13341358
stmts = []
13351359

13361360
class ConnectionWrapper(cluster.connection_class):
1337-
def __init__(self, *args, **kwargs):
1338-
super(ConnectionWrapper, self).__init__(*args, **kwargs)
1339-
13401361
def send_msg(self, msg, request_id, cb, encoder=ProtocolHandler.encode_message,
13411362
decoder=ProtocolHandler.decode_message, result_metadata=None):
13421363
if isinstance(msg, QueryMessage):
@@ -1351,7 +1372,10 @@ def send_msg(self, msg, request_id, cb, encoder=ProtocolHandler.encode_message,
13511372
for stmt in stmts:
13521373
if "SELECT now() FROM system.local WHERE key='local'" in stmt:
13531374
continue
1354-
assert "USING TIMEOUT 2000ms" in stmt, f"query `{stmt}` does not contain `USING TIMEOUT 2000ms`"
1375+
if expected_query_chunk:
1376+
assert expected_query_chunk in stmt, f"query `{stmt}` does not contain `{expected_query_chunk}`"
1377+
else:
1378+
assert 'USING TIMEOUT' not in stmt, f"query `{stmt}` should not contain `USING TIMEOUT`"
13551379

13561380

13571381
class KeyspaceAlterMetadata(unittest.TestCase):

0 commit comments

Comments
 (0)