Skip to content

Commit 05a9015

Browse files
committed
tests: limit memory usage for tests
To avoid situation when the tests eats too much RAM and we spend dozen of time to figure out why MEMORY_LIMIT_EXCEEDED happens on the server. Refs: #75966
1 parent ba99bfe commit 05a9015

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

ci/jobs/functional_stateful_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run_test(
3636
):
3737
test_output_file = f"{temp_dir}/test_result.txt"
3838

39-
test_command = f"clickhouse-test --jobs 2 --testname --shard --zookeeper --check-zookeeper-session --no-stateless \
39+
test_command = f"clickhouse-test --memory-limit {20<<30} --jobs 2 --testname --shard --zookeeper --check-zookeeper-session --no-stateless \
4040
--hung-check --print-time \
4141
--capture-client-stacktrace --queries ./tests/queries -- '{test}' \
4242
| ts '%Y-%m-%d %H:%M:%S' | tee -a \"{test_output_file}\""

ci/jobs/functional_stateless_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def run_stateless_test(
4040
nproc = int(Utils.cpu_count() / 2)
4141
if batch_num and batch_total:
4242
aux = f"--run-by-hash-total {batch_total} --run-by-hash-num {batch_num-1}"
43-
statless_test_command = f"clickhouse-test --testname --shard --zookeeper --check-zookeeper-session --hung-check --print-time \
43+
statless_test_command = f"clickhouse-test --memory-limit {20<<30} --testname --shard --zookeeper --check-zookeeper-session --hung-check --print-time \
4444
--capture-client-stacktrace --queries /repo/tests/queries --test-runs 1 --hung-check \
4545
{'--no-parallel' if no_parallel else ''} {'--no-sequential' if no_sequiential else ''} \
4646
--print-time --jobs {nproc} --report-coverage --report-logs-stats {aux} \

tests/clickhouse-test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,11 @@ def replace_in_file(filename, what, with_what):
11691169
os.system(f"LC_ALL=C sed -i -e 's|{what}|{with_what}|g' {filename}")
11701170

11711171

1172+
def prlimit(command, limit):
1173+
"""Limit memory usage for each test to avoid MEMORY_LIMIT_EXCEEDED errors on server"""
1174+
return f"prlimit --as={limit} {command}"
1175+
1176+
11721177
class TestResult:
11731178
def __init__(
11741179
self,
@@ -1890,6 +1895,8 @@ class TestCase:
18901895
)
18911896

18921897
command = pattern.format(**params)
1898+
if args.memory_limit:
1899+
command = prlimit(command, args.memory_limit)
18931900

18941901
# pylint:disable-next=consider-using-with; TODO: fix
18951902
proc = Popen(command, shell=True, env=os.environ, start_new_session=True)
@@ -3769,6 +3776,12 @@ def parse_args():
37693776
action="store_true",
37703777
help="Capture stacktraces from clickhouse-client/local on errors",
37713778
)
3779+
parser.add_argument(
3780+
"--memory-limit",
3781+
type=int,
3782+
default=5 << 30,
3783+
help="Limit memory for the test (for now it is address space, not a real memory, so the limit could be higher the real memory usage)",
3784+
)
37723785

37733786
return parser.parse_args()
37743787

tests/docker_scripts/fasttest_runner.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ function run_tests
275275
export CLICKHOUSE_SCHEMA_FILES="$FASTTEST_DATA/format_schemas"
276276

277277
local test_opts=(
278+
--memory-limit $((5<<30))
278279
--hung-check
279280
--fast-tests-only
280281
--no-random-settings

tests/docker_scripts/stress_runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fi
266266
start_server
267267

268268
cd /repo/tests/ || exit 1 # clickhouse-test can find queries dir from there
269-
python3 /repo/tests/ci/stress.py --hung-check --drop-databases --output-folder /test_output --skip-func-tests "$SKIP_TESTS_OPTION" --global-time-limit 1200 \
269+
python3 /repo/tests/ci/stress.py --memory-limit $((20<<30)) --hung-check --drop-databases --output-folder /test_output --skip-func-tests "$SKIP_TESTS_OPTION" --global-time-limit 1200 \
270270
&& echo -e "Test script exit code$OK" >> /test_output/test_results.tsv \
271271
|| echo -e "Test script failed$FAIL script exit code: $?" >> /test_output/test_results.tsv
272272

tests/docker_scripts/upgrade_runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ clickhouse-client --query="SELECT 'Server version: ', version()"
111111

112112
mkdir tmp_stress_output
113113

114-
stress --test-cmd="/usr/bin/clickhouse-test --queries=\"previous_release_repository/tests/queries\"" --upgrade-check --output-folder tmp_stress_output --global-time-limit=1200 \
114+
stress --test-cmd="/usr/bin/clickhouse-test --memory-limit $((20<<30)) --queries=\"previous_release_repository/tests/queries\"" --upgrade-check --output-folder tmp_stress_output --global-time-limit=1200 \
115115
&& echo -e "Test script exit code$OK" >> /test_output/test_results.tsv \
116116
|| echo -e "Test script failed$FAIL script exit code: $?" >> /test_output/test_results.tsv
117117

0 commit comments

Comments
 (0)