Skip to content

Commit ea6359f

Browse files
committed
add allow_higher_cpu_wait_ratio helper step
1 parent 06b5db6 commit ea6359f

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

helpers/common.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,3 +1177,61 @@ def repeat_until_stop(self, stop_event: Event, func, delay=0.5):
11771177
while not stop_event.is_set():
11781178
func()
11791179
time.sleep(delay)
1180+
1181+
1182+
@TestStep(Given)
1183+
def allow_higher_cpu_wait_ratio(
1184+
self, min_os_cpu_wait_time_ratio_to_throw=10, max_os_cpu_wait_time_ratio_to_throw=20
1185+
):
1186+
"""
1187+
Temporarily increase the threshold for OS CPU wait time ratio
1188+
to reduce the chance of query rejection due to system overload.
1189+
1190+
This step updates the default query settings for the test context
1191+
by increasing the min and max OS CPU wait-to-busy time ratios.
1192+
1193+
Useful for tests that are expected to put high load on the system
1194+
and may otherwise be rejected due to CPU pressure.
1195+
1196+
Args:
1197+
min_ratio (float): Minimum ratio at which query rejection starts (default=10).
1198+
max_ratio (float): Maximum ratio at which rejection probability becomes 100% (default=20).
1199+
"""
1200+
min_os_cpu_wait_time_ratio_to_throw_setting = (
1201+
"min_os_cpu_wait_time_ratio_to_throw",
1202+
min_os_cpu_wait_time_ratio_to_throw,
1203+
)
1204+
max_os_cpu_wait_time_ratio_to_throw_setting = (
1205+
"max_os_cpu_wait_time_ratio_to_throw",
1206+
max_os_cpu_wait_time_ratio_to_throw,
1207+
)
1208+
default_query_settings = None
1209+
1210+
try:
1211+
with By(
1212+
"adding relaxed OS CPU wait ratio thresholds to default query settings"
1213+
):
1214+
default_query_settings = getsattr(
1215+
current().context, "default_query_settings", []
1216+
)
1217+
default_query_settings.append(min_os_cpu_wait_time_ratio_to_throw_setting)
1218+
default_query_settings.append(max_os_cpu_wait_time_ratio_to_throw_setting)
1219+
yield
1220+
finally:
1221+
with Finally(
1222+
"removing the relaxed OS CPU wait ratio settings from default query settings"
1223+
):
1224+
if default_query_settings:
1225+
try:
1226+
default_query_settings.pop(
1227+
default_query_settings.index(
1228+
min_os_cpu_wait_time_ratio_to_throw_setting
1229+
)
1230+
)
1231+
default_query_settings.pop(
1232+
default_query_settings.index(
1233+
max_os_cpu_wait_time_ratio_to_throw_setting
1234+
)
1235+
)
1236+
except ValueError:
1237+
pass

selects/regression.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ def regression(
197197
for node in nodes["clickhouse"]:
198198
experimental_analyzer(node=cluster.node(node), with_analyzer=with_analyzer)
199199

200+
with And("allow higher cpu_wait_ratio "):
201+
if check_clickhouse_version(">=25.4")(self):
202+
allow_higher_cpu_wait_ratio(
203+
min_os_cpu_wait_time_ratio_to_throw=10,
204+
max_os_cpu_wait_time_ratio_to_throw=20,
205+
)
206+
200207
Feature(run=load("selects.tests.final.feature", "module"))
201208

202209

0 commit comments

Comments
 (0)