Skip to content

Commit

Permalink
Merge pull request #467 from Altinity/testflows_test_updates
Browse files Browse the repository at this point in the history
Testflows test updates
  • Loading branch information
Selfeer authored Feb 21, 2024
2 parents 6723206 + 3d8c0b7 commit b831fed
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@
"https://github.com/Altinity/clickhouse-sink-connector/issues/461",
)
],
"/mysql to clickhouse replication/mysql to clickhouse replication auto/datatypes/datetime/*": [
(
Fail,
"https://github.com/Altinity/clickhouse-sink-connector/issues/462",
)
],
"types/enum": [(Fail, "doesn't create table")],
}
xflags = {}
Expand Down
88 changes: 64 additions & 24 deletions sink-connector-lightweight/tests/integration/tests/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
from integration.tests.steps.sql import *


def adjust_precision(datetime_str, precision):
"""A function to transform given DATETIME values from MySQL to ClickHouse with given precision."""
if datetime_str == "NOW()":
return datetime_str

parts = datetime_str.split(".")
main_part = parts[0]

if precision == "0":
return main_part

if len(parts) == 1:
return f"{main_part}.{'0' * int(precision)}"

microseconds_part = parts[1]
adjusted_microseconds = microseconds_part[: int(precision)].ljust(
int(precision), "0"
)

return f"{main_part}.{adjusted_microseconds}"


@TestStep(Given)
def create_table_with_datetime_column(self, table_name, data, precision):
"""Create MySQL table that contains the datetime column."""
Expand All @@ -20,14 +42,19 @@ def create_table_with_datetime_column(self, table_name, data, precision):
)

with And(f"inserting data to MySQL {table_name} table"):
mysql_node.query(f"INSERT INTO {table_name} VALUES (1, '{data}');")
if data != "NOW()":
mysql_node.query(f"INSERT INTO {table_name} VALUES (1, '{data}');")
else:
mysql_node.query(f"INSERT INTO {table_name} VALUES (1, {data});")


@TestCheck
def check_datetime_column(self, precision, data):
table_name = "table_" + getuid()
clickhouse_node = self.context.clickhouse_node

data = adjust_precision(datetime_str=data, precision=precision)

with Given(
"I create a table with datetime column",
description=f"""
Expand All @@ -42,29 +69,42 @@ def check_datetime_column(self, precision, data):
with Then(f"I check that the data is replicated to ClickHouse and is not lost"):
for retry in retries(timeout=30):
with retry:
if data == "1000-01-01 00:00:00" or data == "1900-01-01 00:00:00":
clickhouse_values = clickhouse_node.query(
f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV"
)
assert (
clickhouse_values.output.strip().replace('"', "")
== "1900-01-01 00:00:00"
), error()
elif data == "9999-12-31 23:59:59" or data == "2299-12-31 23:59:59":
clickhouse_values = clickhouse_node.query(
f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV"
)
assert (
clickhouse_values.output.strip().replace('"', "")
== "2299-12-31 23:59:59"
), error()
else:
clickhouse_values = clickhouse_node.query(
f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV"
)
assert (
clickhouse_values.output.strip().replace('"', "") == data
), error()
clickhouse_values = clickhouse_node.query(
f"SELECT count(date) FROM {self.context.database}.{table_name} FORMAT CSV"
)

assert clickhouse_values.output.strip() != "0", error()

if data == "NOW()":
clickhouse_values = clickhouse_node.query(
f"SELECT count(date) FROM {self.context.database}.{table_name} FORMAT CSV"
)
assert clickhouse_values.output.strip() != "0", error()

elif data == "1000-01-01 00:00:00" or data == "1900-01-01 00:00:00":
clickhouse_values = clickhouse_node.query(
f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV"
)
assert clickhouse_values.output.strip().replace(
'"', ""
) == adjust_precision(
datetime_str="1900-01-01 00:00:00", precision=precision
), error()

elif data == "9999-12-31 23:59:59" or data == "2299-12-31 23:59:59":
clickhouse_values = clickhouse_node.query(
f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV"
)
assert clickhouse_values.output.strip().replace(
'"', ""
) == adjust_precision(
datetime_str="2299-12-31 23:59:59", precision=precision
), error()
else:
clickhouse_values = clickhouse_node.query(
f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV"
)
assert clickhouse_values.output.strip().replace('"', "") == data, error()


@TestSketch(Scenario)
Expand Down

0 comments on commit b831fed

Please sign in to comment.