From 051d1a5f0784117cc1967e2a9c8cdb279b286e8b Mon Sep 17 00:00:00 2001 From: bharatnc Date: Fri, 11 Sep 2020 20:43:47 -0700 Subject: [PATCH] TraceLog - replace unit test with integration test --- .../test_trace_log_table/__init__.py | 0 .../configs/trace_log.xml | 8 +++ .../integration/test_trace_log_table/test.py | 65 +++++++++++++++++++ .../01473_event_time_microseconds.reference | 2 - .../01473_event_time_microseconds.sql | 17 ----- 5 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 tests/integration/test_trace_log_table/__init__.py create mode 100644 tests/integration/test_trace_log_table/configs/trace_log.xml create mode 100644 tests/integration/test_trace_log_table/test.py diff --git a/tests/integration/test_trace_log_table/__init__.py b/tests/integration/test_trace_log_table/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_trace_log_table/configs/trace_log.xml b/tests/integration/test_trace_log_table/configs/trace_log.xml new file mode 100644 index 0000000000..48a93dc0cb --- /dev/null +++ b/tests/integration/test_trace_log_table/configs/trace_log.xml @@ -0,0 +1,8 @@ + + + system + trace_log
+ toYYYYMM(event_date) + 1000 +
+
diff --git a/tests/integration/test_trace_log_table/test.py b/tests/integration/test_trace_log_table/test.py new file mode 100644 index 0000000000..9f68e4b444 --- /dev/null +++ b/tests/integration/test_trace_log_table/test.py @@ -0,0 +1,65 @@ +# pylint: disable=unused-argument +# pylint: disable=redefined-outer-name +import time + +import pytest +from helpers.cluster import ClickHouseCluster + +cluster = ClickHouseCluster(__file__) + +node = cluster.add_instance('node', with_zookeeper=True, main_configs=["configs/trace_log.xml"]) + + +@pytest.fixture(scope='module') +def start_cluster(): + try: + cluster.start() + + yield cluster + finally: + cluster.shutdown() + + +# Tests that the event_time_microseconds field in the system.trace_log table gets populated. +# To make the tests work better, the default flush_interval_milliseconds is being overridden +# to 1000 ms. Also the query_profiler_real_time_period_ns and the query_profiler_cpu_time_period_ns +# are set to suitable values so that traces are properly populated. Test compares the event_time and +# event_time_microseconds fields and asserts that they are exactly equal upto their seconds parts. Also +# one additional test to ensure that the count(event_time_microseconds) is > 0; +def test_field_event_time_microseconds(start_cluster): + node.query('SET query_profiler_real_time_period_ns = 0;') + node.query('SET query_profiler_cpu_time_period_ns = 1000000;') + node.query('SET log_queries = 1;') + node.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;''' + node.query(query_create) + node.query('''INSERT INTO replica.test VALUES (1, now())''') + node.query("SYSTEM FLUSH LOGS;") + # TODO: is sleep necessary ? + time.sleep(1) + # query assumes that the event_time field is already accurate + equals_query = '''WITH ( + ( + SELECT event_time_microseconds + FROM system.trace_log + ORDER BY event_time DESC + LIMIT 1 + ) AS time_with_microseconds, + ( + SELECT event_time + FROM system.trace_log + ORDER BY event_time DESC + LIMIT 1 + ) AS t) + SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(t)) = 0, 'ok', 'fail') + ''' + assert 'ok\n' in node.query(equals_query) + assert 'ok\n' in node.query( + '''SELECT if((SELECT COUNT(event_time_microseconds) FROM system.trace_log) > 0, 'ok', 'fail')''') diff --git a/tests/queries/0_stateless/01473_event_time_microseconds.reference b/tests/queries/0_stateless/01473_event_time_microseconds.reference index 6d95c8c1b8..7da9f21de2 100644 --- a/tests/queries/0_stateless/01473_event_time_microseconds.reference +++ b/tests/queries/0_stateless/01473_event_time_microseconds.reference @@ -1,7 +1,5 @@ 01473_metric_log_table_event_start_time_microseconds_test ok -01473_trace_log_table_event_start_time_microseconds_test -ok 01473_query_log_table_event_start_time_microseconds_test ok 01473_query_thread_log_table_event_start_time_microseconds_test diff --git a/tests/queries/0_stateless/01473_event_time_microseconds.sql b/tests/queries/0_stateless/01473_event_time_microseconds.sql index 537664b1ef..48d620be19 100644 --- a/tests/queries/0_stateless/01473_event_time_microseconds.sql +++ b/tests/queries/0_stateless/01473_event_time_microseconds.sql @@ -23,23 +23,6 @@ WITH ( ) AS time) SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(time)) = 0, 'ok', 'fail'); -SELECT '01473_trace_log_table_event_start_time_microseconds_test'; -SYSTEM FLUSH LOGS; -WITH ( - ( - SELECT event_time_microseconds - FROM system.trace_log - ORDER BY event_time DESC - LIMIT 1 - ) AS time_with_microseconds, - ( - SELECT event_time - FROM system.trace_log - ORDER BY event_time DESC - LIMIT 1 - ) AS time) -SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(time)) = 0, 'ok', 'fail'); -- success - SELECT '01473_query_log_table_event_start_time_microseconds_test'; SYSTEM FLUSH LOGS; WITH ( -- GitLab