Add tests

This commit is contained in:
Aleksei Filatov 2023-08-03 12:45:07 +03:00
parent 4734d416a5
commit 0fc0a89f80
2 changed files with 61 additions and 0 deletions

View File

@ -1,10 +1,12 @@
import inspect
from contextlib import nullcontext as does_not_raise
import pytest
import time
import os.path
from helpers.cluster import ClickHouseCluster
from helpers.client import QueryRuntimeException
from helpers.test_tools import assert_eq_with_retry, TSV
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
@ -83,6 +85,33 @@ def test_create_and_drop():
node1.query("DROP FUNCTION f1")
@pytest.mark.parametrize(
"ignore, expected_raise",
[("true", does_not_raise()), ("false", pytest.raises(QueryRuntimeException))],
)
def test_create_and_drop_udf_on_cluster(ignore, expected_raise):
node1.replace_config(
"/etc/clickhouse-server/users.d/users.xml",
inspect.cleandoc(
f"""
<clickhouse>
<profiles>
<default>
<ignore_on_cluster_for_replicated_udf_queries>{ignore}</ignore_on_cluster_for_replicated_udf_queries>
</default>
</profiles>
</clickhouse>
"""
),
)
node1.query("SYSTEM RELOAD CONFIG")
with expected_raise:
node1.query("CREATE FUNCTION f1 ON CLUSTER default AS (x, y) -> x + y")
assert node1.query("SELECT f1(12, 3)") == "15\n"
node1.query("DROP FUNCTION f1 ON CLUSTER default")
def test_create_and_replace():
node1.query("CREATE FUNCTION f1 AS (x, y) -> x + y")
assert node1.query("SELECT f1(12, 3)") == "15\n"

View File

@ -1,3 +1,4 @@
import inspect
import pytest
import time
@ -82,6 +83,37 @@ def test_create_replicated_on_cluster(started_cluster, entity):
node1.query(f"DROP {entity.keyword} {entity.name} {entity.options}")
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
def test_create_replicated_on_cluster_ignore(started_cluster, entity):
node1.replace_config(
"/etc/clickhouse-server/users.d/users.xml",
inspect.cleandoc(
f"""
<clickhouse>
<profiles>
<default>
<ignore_on_cluster_for_replicated_access_entities_queries>true</ignore_on_cluster_for_replicated_access_entities_queries>
</default>
</profiles>
</clickhouse>
"""
),
)
node1.query("SYSTEM RELOAD CONFIG")
node1.query(
f"CREATE {entity.keyword} {entity.name} ON CLUSTER default {entity.options}"
)
assert (
f"cannot insert because {entity.keyword.lower()} `{entity.name}{entity.options}` already exists in replicated"
in node2.query_and_get_error_with_retry(
f"CREATE {entity.keyword} {entity.name} {entity.options}"
)
)
node1.query(f"DROP {entity.keyword} {entity.name} {entity.options}")
@pytest.mark.parametrize("entity", entities, ids=get_entity_id)
def test_create_replicated_if_not_exists_on_cluster(started_cluster, entity):
node1.query(