2021-03-03 17:47:27 +00:00
|
|
|
import os.path
|
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
2024-09-27 10:19:39 +00:00
|
|
|
|
2021-03-03 17:47:27 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
from helpers.test_tools import TSV
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
|
|
NODES = {"node" + str(i): None for i in (1, 2)}
|
|
|
|
|
2021-09-25 04:08:34 +00:00
|
|
|
config = """<clickhouse>
|
2021-03-03 17:47:27 +00:00
|
|
|
<profiles>
|
|
|
|
<default>
|
2021-03-26 07:05:56 +00:00
|
|
|
<sleep_in_send_data_ms>{sleep_in_send_data_ms}</sleep_in_send_data_ms>
|
2021-03-03 17:47:27 +00:00
|
|
|
</default>
|
|
|
|
</profiles>
|
2021-09-25 04:08:34 +00:00
|
|
|
</clickhouse>"""
|
2021-03-03 17:47:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
cluster.__with_ssl_config = True
|
|
|
|
main_configs = [
|
|
|
|
"configs_secure/config.d/remote_servers.xml",
|
|
|
|
"configs_secure/server.crt",
|
|
|
|
"configs_secure/server.key",
|
|
|
|
"configs_secure/dhparam.pem",
|
|
|
|
"configs_secure/config.d/ssl_conf.xml",
|
|
|
|
]
|
|
|
|
|
|
|
|
NODES["node1"] = cluster.add_instance("node1", main_configs=main_configs)
|
|
|
|
NODES["node2"] = cluster.add_instance(
|
|
|
|
"node2",
|
|
|
|
main_configs=main_configs,
|
|
|
|
user_configs=["configs_secure/users.d/users.xml"],
|
|
|
|
)
|
2021-03-05 16:08:49 +00:00
|
|
|
|
2021-03-03 17:47:27 +00:00
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
NODES["node2"].query(
|
|
|
|
"CREATE TABLE base_table (x UInt64) ENGINE = MergeTree ORDER BY x;"
|
|
|
|
)
|
|
|
|
NODES["node2"].query("INSERT INTO base_table VALUES (5);")
|
|
|
|
NODES["node1"].query(
|
|
|
|
"CREATE TABLE distributed_table (x UInt64) ENGINE = Distributed(test_cluster, default, base_table);"
|
|
|
|
)
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test(started_cluster):
|
2021-03-26 07:05:56 +00:00
|
|
|
NODES["node2"].replace_config(
|
|
|
|
"/etc/clickhouse-server/users.d/users.xml",
|
|
|
|
config.format(sleep_in_send_data_ms=1000000),
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2023-06-26 01:04:48 +00:00
|
|
|
if NODES["node1"].is_built_with_thread_sanitizer():
|
2023-06-26 01:24:09 +00:00
|
|
|
pytest.skip("Hedged requests don't work under Thread Sanitizer")
|
2023-06-26 01:04:48 +00:00
|
|
|
|
2021-03-03 17:47:27 +00:00
|
|
|
attempts = 0
|
|
|
|
while attempts < 1000:
|
2021-03-26 07:05:56 +00:00
|
|
|
setting = NODES["node2"].http_query(
|
|
|
|
"SELECT value FROM system.settings WHERE name='sleep_in_send_data_ms'"
|
|
|
|
)
|
|
|
|
if int(setting) == 1000000:
|
2021-03-03 17:47:27 +00:00
|
|
|
break
|
|
|
|
time.sleep(0.1)
|
|
|
|
attempts += 1
|
|
|
|
|
|
|
|
assert attempts < 1000
|
|
|
|
|
|
|
|
start = time.time()
|
2021-03-30 07:51:44 +00:00
|
|
|
NODES["node1"].query_and_get_error(
|
|
|
|
"SELECT * FROM distributed_table settings receive_timeout=5, send_timeout=5, use_hedged_requests=0, async_socket_for_remote=0;"
|
|
|
|
)
|
2021-03-03 17:47:27 +00:00
|
|
|
end = time.time()
|
2021-03-05 13:18:12 +00:00
|
|
|
assert end - start < 10
|
2021-03-03 17:47:27 +00:00
|
|
|
|
|
|
|
start = time.time()
|
2021-04-19 08:46:42 +00:00
|
|
|
error = NODES["node1"].query_and_get_error(
|
|
|
|
"SELECT * FROM distributed_table settings receive_timeout=5, send_timeout=5, use_hedged_requests=0, async_socket_for_remote=1;"
|
|
|
|
)
|
2021-03-03 17:47:27 +00:00
|
|
|
end = time.time()
|
|
|
|
|
2021-03-05 13:18:12 +00:00
|
|
|
assert end - start < 10
|
2021-03-03 17:47:27 +00:00
|
|
|
|
|
|
|
# Check that exception about timeout wasn't thrown from DB::ReadBufferFromPocoSocket::nextImpl().
|
|
|
|
assert error.find("DB::ReadBufferFromPocoSocket::nextImpl()") == -1
|
|
|
|
|
|
|
|
start = time.time()
|
2021-04-19 08:46:42 +00:00
|
|
|
error = NODES["node1"].query_and_get_error(
|
|
|
|
"SELECT * FROM distributed_table settings receive_timeout=5, send_timeout=5, use_hedged_requests=1, async_socket_for_remote=1;"
|
|
|
|
)
|
2021-03-03 17:47:27 +00:00
|
|
|
end = time.time()
|
|
|
|
|
2021-03-05 13:18:12 +00:00
|
|
|
assert end - start < 10
|
2021-03-03 17:47:27 +00:00
|
|
|
|
|
|
|
# Check that exception about timeout wasn't thrown from DB::ReadBufferFromPocoSocket::nextImpl().
|
|
|
|
assert error.find("DB::ReadBufferFromPocoSocket::nextImpl()") == -1
|