try fix test

This commit is contained in:
Alexander Tokmakov 2020-09-27 16:25:28 +03:00
parent 4f8266c7a1
commit 7486539862
7 changed files with 66 additions and 108 deletions

View File

@ -0,0 +1,33 @@
# pylint: disable=unused-argument
# pylint: disable=redefined-outer-name
import pytest
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance('node', main_configs=["configs/config.d/text_log.xml"])
@pytest.fixture(scope='module')
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_basic(start_cluster):
with pytest.raises(QueryRuntimeException):
# generates log with "Error" level
node.query('SELECT * FROM no_such_table')
node.query('SYSTEM FLUSH LOGS')
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Trace'")) == 0
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Debug'")) == 0
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Information'")) >= 1
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Error'")) >= 1

View File

@ -1,57 +0,0 @@
# pylint: disable=unused-argument
# pylint: disable=redefined-outer-name
import pytest
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance('node', main_configs=["configs/config.d/text_log.xml"])
@pytest.fixture(scope='module')
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_basic(start_cluster):
with pytest.raises(QueryRuntimeException):
# generate log with "Error" level
node.query('SELECT * FROM no_such_table')
node.query('SYSTEM FLUSH LOGS')
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Trace'")) == 0
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Debug'")) == 0
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Information'")) >= 1
assert int(node.query("SELECT count() FROM system.text_log WHERE level = 'Error'")) >= 1
# compare the event_time and event_time_microseconds and test
# that they are exactly equal upto their seconds parts.
def test_field_event_time_microseconds(start_cluster):
with pytest.raises(QueryRuntimeException):
# generate log with "Error" level
node.query('SELECT * FROM no_such_table')
node.query('SYSTEM FLUSH LOGS')
equals_query = '''WITH (
(
SELECT event_time_microseconds
FROM system.text_log
ORDER BY event_time DESC
LIMIT 1
) AS time_with_microseconds,
(
SELECT event_time
FROM system.text_log
ORDER BY event_time DESC
LIMIT 1
) AS time)
SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(time)) = 0, 'ok', 'fail')
'''
assert 'ok\n' in node.query(equals_query)

View File

@ -6,3 +6,5 @@ ok
ok
01473_query_thread_log_table_event_start_time_microseconds_test
ok
01473_text_log_table_event_start_time_microseconds_test
ok

View File

@ -4,79 +4,54 @@
-- Refer: tests/integration/test_asynchronous_metric_log_table.
SET log_queries = 1;
SET query_profiler_real_time_period_ns = 100000000;
-- a long enough query to trigger the query profiler and to record trace log
SELECT sleep(2) FORMAT Null;
SET query_profiler_real_time_period_ns = 1000000000;
SYSTEM FLUSH LOGS;
SELECT '01473_metric_log_table_event_start_time_microseconds_test';
SYSTEM FLUSH LOGS;
-- query assumes that the event_time field is accurate.
WITH (
(
SELECT event_time_microseconds
SELECT event_time_microseconds, event_time
FROM system.metric_log
ORDER BY event_time DESC
LIMIT 1
) AS time_with_microseconds,
(
SELECT event_time
FROM system.metric_log
ORDER BY event_time DESC
LIMIT 1
) AS time)
SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(time)) = 0, 'ok', 'fail');
) AS time
SELECT if(dateDiff('second', toDateTime(time.1), toDateTime(time.2)) = 0, 'ok', toString(time));
SELECT '01473_trace_log_table_event_start_time_microseconds_test';
SET log_queries = 1;
SET query_profiler_real_time_period_ns = 10000000;
SET query_profiler_cpu_time_period_ns = 10000000;
-- a long enough query to trigger the query profiler and to record trace log
SELECT count() FROM numbers(1000000000) FORMAT Null;
SELECT sleep(2) FORMAT Null;
SYSTEM FLUSH LOGS;
SELECT sleep(2) FORMAT Null;
WITH (
(
SELECT event_time_microseconds
SELECT event_time_microseconds, event_time
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'); -- success
) AS time
SELECT if(dateDiff('second', toDateTime(time.1), toDateTime(time.2)) = 0, 'ok', toString(time));
SELECT '01473_query_log_table_event_start_time_microseconds_test';
SYSTEM FLUSH LOGS;
WITH (
(
SELECT event_time_microseconds
SELECT event_time_microseconds, event_time
FROM system.query_log
ORDER BY event_time DESC
LIMIT 1
) AS time_with_microseconds,
(
SELECT event_time
FROM system.query_log
ORDER BY event_time DESC
LIMIT 1
) AS time)
SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(time)) = 0, 'ok', 'fail'); -- success
) AS time
SELECT if(dateDiff('second', toDateTime(time.1), toDateTime(time.2)) = 0, 'ok', toString(time));
SELECT '01473_query_thread_log_table_event_start_time_microseconds_test';
SYSTEM FLUSH LOGS;
WITH (
(
SELECT event_time_microseconds
SELECT event_time_microseconds, event_time
FROM system.query_thread_log
ORDER BY event_time DESC
LIMIT 1
) AS time_with_microseconds,
(
SELECT event_time
FROM system.query_thread_log
ORDER BY event_time DESC
LIMIT 1
) AS time)
SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(time)) = 0, 'ok', 'fail'); -- success
) AS time
SELECT if(dateDiff('second', toDateTime(time.1), toDateTime(time.2)) = 0, 'ok', toString(time));
SELECT '01473_text_log_table_event_start_time_microseconds_test';
WITH (
SELECT event_time_microseconds, event_time
FROM system.query_thread_log
ORDER BY event_time DESC
LIMIT 1
) AS time
SELECT if(dateDiff('second', toDateTime(time.1), toDateTime(time.2)) = 0, 'ok', toString(time));

View File

@ -17,6 +17,7 @@
"00151_replace_partition_with_different_granularity",
"00157_cache_dictionary",
"01193_metadata_loading",
"01473_event_time_microseconds",
"01474_executable_dictionary" /// informational stderr from sanitizer at start
],
"address-sanitizer": [
@ -25,6 +26,7 @@
"memory_profiler",
"odbc_roundtrip",
"01103_check_cpu_instructions_at_startup",
"01473_event_time_microseconds",
"01193_metadata_loading"
],
"ub-sanitizer": [
@ -33,6 +35,7 @@
"memory_profiler",
"01103_check_cpu_instructions_at_startup",
"00900_orc_load",
"01473_event_time_microseconds",
"01193_metadata_loading"
],
"memory-sanitizer": [
@ -43,6 +46,7 @@
"01086_odbc_roundtrip", /// can't pass because odbc libraries are not instrumented
"00877_memory_limit_for_new_delete", /// memory limits don't work correctly under msan because it replaces malloc/free
"01114_mysql_database_engine_segfault", /// it fails in _nss_files_parse_servent while using NSS from GLibc to authenticate (need to get rid of it)
"01473_event_time_microseconds",
"01193_metadata_loading"
],
"debug-build": [
@ -57,6 +61,7 @@
"01037_polygon_dicts_",
"hyperscan",
"01193_metadata_loading",
"01473_event_time_microseconds",
"01396_inactive_replica_cleanup_nodes"
],
"unbundled-build": [