mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Merge pull request #44978 from azat/tests/fix-test_replicated_users
tests: fix test_replicated_users flakiness
This commit is contained in:
commit
590ad41cbf
@ -3225,6 +3225,40 @@ class ClickHouseInstance:
|
|||||||
database=database,
|
database=database,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def query_and_get_error_with_retry(
|
||||||
|
self,
|
||||||
|
sql,
|
||||||
|
stdin=None,
|
||||||
|
timeout=None,
|
||||||
|
settings=None,
|
||||||
|
user=None,
|
||||||
|
password=None,
|
||||||
|
database=None,
|
||||||
|
retry_count=20,
|
||||||
|
sleep_time=0.5,
|
||||||
|
):
|
||||||
|
logging.debug(f"Executing query {sql} on {self.name}")
|
||||||
|
result = None
|
||||||
|
for i in range(retry_count):
|
||||||
|
try:
|
||||||
|
result = self.client.query_and_get_error(
|
||||||
|
sql,
|
||||||
|
stdin=stdin,
|
||||||
|
timeout=timeout,
|
||||||
|
settings=settings,
|
||||||
|
user=user,
|
||||||
|
password=password,
|
||||||
|
database=database,
|
||||||
|
)
|
||||||
|
time.sleep(sleep_time)
|
||||||
|
except QueryRuntimeException as ex:
|
||||||
|
logging.debug("Retry {} got exception {}".format(i + 1, ex))
|
||||||
|
time.sleep(sleep_time)
|
||||||
|
|
||||||
|
if result is not None:
|
||||||
|
return result
|
||||||
|
raise Exception("Query {sql} did not fail".format(sql))
|
||||||
|
|
||||||
# The same as query_and_get_error but ignores successful query.
|
# The same as query_and_get_error but ignores successful query.
|
||||||
def query_and_get_answer_with_error(
|
def query_and_get_answer_with_error(
|
||||||
self,
|
self,
|
||||||
|
@ -58,7 +58,7 @@ def test_create_replicated(started_cluster, entity):
|
|||||||
node1.query(f"CREATE {entity.keyword} {entity.name} {entity.options}")
|
node1.query(f"CREATE {entity.keyword} {entity.name} {entity.options}")
|
||||||
assert (
|
assert (
|
||||||
f"cannot insert because {entity.keyword.lower()} `{entity.name}{entity.options}` already exists in replicated"
|
f"cannot insert because {entity.keyword.lower()} `{entity.name}{entity.options}` already exists in replicated"
|
||||||
in node2.query_and_get_error(
|
in node2.query_and_get_error_with_retry(
|
||||||
f"CREATE {entity.keyword} {entity.name} {entity.options}"
|
f"CREATE {entity.keyword} {entity.name} {entity.options}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -68,7 +68,7 @@ def test_create_replicated(started_cluster, entity):
|
|||||||
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
|
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
|
||||||
def test_create_and_delete_replicated(started_cluster, entity):
|
def test_create_and_delete_replicated(started_cluster, entity):
|
||||||
node1.query(f"CREATE {entity.keyword} {entity.name} {entity.options}")
|
node1.query(f"CREATE {entity.keyword} {entity.name} {entity.options}")
|
||||||
node2.query(f"DROP {entity.keyword} {entity.name} {entity.options}")
|
node2.query_with_retry(f"DROP {entity.keyword} {entity.name} {entity.options}")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
|
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
|
||||||
@ -93,7 +93,7 @@ def test_create_replicated_if_not_exists_on_cluster(started_cluster, entity):
|
|||||||
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
|
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
|
||||||
def test_rename_replicated(started_cluster, entity):
|
def test_rename_replicated(started_cluster, entity):
|
||||||
node1.query(f"CREATE {entity.keyword} {entity.name} {entity.options}")
|
node1.query(f"CREATE {entity.keyword} {entity.name} {entity.options}")
|
||||||
node2.query(
|
node2.query_with_retry(
|
||||||
f"ALTER {entity.keyword} {entity.name} {entity.options} RENAME TO {entity.name}2"
|
f"ALTER {entity.keyword} {entity.name} {entity.options} RENAME TO {entity.name}2"
|
||||||
)
|
)
|
||||||
node1.query(f"DROP {entity.keyword} {entity.name}2 {entity.options}")
|
node1.query(f"DROP {entity.keyword} {entity.name}2 {entity.options}")
|
||||||
|
Loading…
Reference in New Issue
Block a user