ClickHouse/tests/integration/test_memory_limit_observer/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.5 KiB
Python
Raw Normal View History

2024-03-12 22:31:33 +00:00
import pytest
import logging
import time
from helpers.cluster import ClickHouseCluster, run_and_check
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance(
2024-03-13 05:40:47 +00:00
"node1", main_configs=["config/text_log.xml"], mem_limit="5g"
2024-03-12 22:31:33 +00:00
)
2024-03-13 05:40:47 +00:00
2024-03-12 22:31:33 +00:00
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
2024-03-13 05:40:47 +00:00
2024-03-12 22:31:33 +00:00
def get_latest_mem_limit():
for _ in range(10):
try:
2024-03-13 05:40:47 +00:00
mem_limit = float(
node1.query(
"""
select extract(message, '\\d+\\.\\d+') from system.text_log
where message like '%Setting max_server_memory_usage was set to%' and
message not like '%like%' order by event_time desc limit 1
"""
).strip()
)
2024-03-12 22:31:33 +00:00
return mem_limit
except Exception as e:
time.sleep(1)
raise Exception("Cannot get memory limit")
2024-03-13 06:28:41 +00:00
2024-03-12 22:31:33 +00:00
def test_observe_memory_limit(started_cluster):
original_max_mem = get_latest_mem_limit()
logging.debug(f"get original memory limit {original_max_mem}")
2024-03-13 06:28:41 +00:00
run_and_check(["docker", "update", "--memory=10g", node1.docker_id])
2024-03-12 22:31:33 +00:00
for _ in range(30):
time.sleep(10)
2024-03-13 05:40:47 +00:00
new_max_mem = get_latest_mem_limit()
2024-03-12 22:31:33 +00:00
logging.debug(f"get new memory limit {new_max_mem}")
if new_max_mem > original_max_mem:
return
2024-03-15 20:00:42 +00:00
raise Exception("the memory limit does not increase as expected")