diff --git a/tests/integration/test_asynchronous_metric_log_table/__init__.py b/tests/integration/test_asynchronous_metric_log_table/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/integration/test_asynchronous_metric_log_table/configs/asynchronous_metrics_update_period_s.xml b/tests/integration/test_asynchronous_metric_log_table/configs/asynchronous_metrics_update_period_s.xml new file mode 100644 index 00000000000..840c19f03a6 --- /dev/null +++ b/tests/integration/test_asynchronous_metric_log_table/configs/asynchronous_metrics_update_period_s.xml @@ -0,0 +1,3 @@ + + 2 + diff --git a/tests/integration/test_asynchronous_metric_log_table/test.py b/tests/integration/test_asynchronous_metric_log_table/test.py new file mode 100644 index 00000000000..10face9abc6 --- /dev/null +++ b/tests/integration/test_asynchronous_metric_log_table/test.py @@ -0,0 +1,32 @@ +import time + +from helpers.cluster import ClickHouseCluster + +# Tests that the event_time_microseconds field in system.asynchronous_metric_log table gets populated. +# asynchronous metrics are updated once every 60s by default. To make the test run faster, the setting +# asynchronous_metric_update_period_s is being set to 2s so that the metrics are populated faster and +# are available for querying during the test. +def test_asynchronous_metric_log(): + cluster = ClickHouseCluster(__file__) + node1 = cluster.add_instance('node1', with_zookeeper=True, main_configs=['configs/asynchronous_metrics_update_period_s.xml']) + try: + cluster.start() + node1.query("SET log_queries = 1;") + node1.query("CREATE DATABASE replica;") + query_create = '''CREATE TABLE replica.test + ( + id Int64, + event_time DateTime + ) + Engine=MergeTree() + PARTITION BY toYYYYMMDD(event_time) + ORDER BY id;''' + time.sleep(2) + node1.query(query_create) + node1.query('''INSERT INTO replica.test VALUES (1, now())''') + node1.query("SYSTEM FLUSH LOGS;") + node1.query("SELECT * FROM system.asynchronous_metrics LIMIT 10") + assert "1\n" in node1.query('''SELECT count() from replica.test FORMAT TSV''') + assert "ok\n" in node1.query("SELECT If((select count(event_time_microseconds) from system.asynchronous_metric_log) > 0, 'ok', 'fail');") + finally: + cluster.shutdown() diff --git a/tests/queries/0_stateless/01473_event_time_microseconds.reference b/tests/queries/0_stateless/01473_event_time_microseconds.reference index cac87f32a29..8aa31f9ab6a 100644 --- a/tests/queries/0_stateless/01473_event_time_microseconds.reference +++ b/tests/queries/0_stateless/01473_event_time_microseconds.reference @@ -1,4 +1,2 @@ -01473_asynchronous_metric_log_event_start_time_milliseconds_test -ok -01473_metric_log_event_start_time_milliseconds_test +01473_metric_log_table_event_start_time_microseconds_test ok diff --git a/tests/queries/0_stateless/01473_event_time_microseconds.sql b/tests/queries/0_stateless/01473_event_time_microseconds.sql index 6a13d6e1543..9bafd3bdbda 100644 --- a/tests/queries/0_stateless/01473_event_time_microseconds.sql +++ b/tests/queries/0_stateless/01473_event_time_microseconds.sql @@ -1,9 +1,11 @@ +-- This file contains tests for the event_time_microseconds field for various tables. +-- Note: Only event_time_microseconds for asynchronous_metric_log table is tested via +-- an integration test as those metrics take 60s by default to be updated. +-- Refer: tests/integration/test_asynchronous_metric_log_table. + set log_queries = 1; -select '01473_asynchronous_metric_log_event_start_time_milliseconds_test'; -system flush logs; -SELECT If((select count(event_time_microseconds) from system.asynchronous_metric_log) > 0, 'ok', 'fail'); -- success - -select '01473_metric_log_event_start_time_milliseconds_test'; +select '01473_metric_log_table_event_start_time_microseconds_test'; system flush logs; +SELECT sleep(3) Format Null; SELECT If((select count(event_time_microseconds) from system.metric_log) > 0, 'ok', 'fail'); -- success