2022-02-15 00:29:55 +00:00
import pytest
from helpers . cluster import ClickHouseCluster
cluster = ClickHouseCluster ( __file__ )
2022-03-22 16:39:58 +00:00
node = cluster . add_instance (
" node " , main_configs = [ " configs/global_overcommit_tracker.xml " ]
)
2022-02-15 00:29:55 +00:00
2022-03-22 16:39:58 +00:00
@pytest.fixture ( scope = " module " , autouse = True )
2022-02-15 00:29:55 +00:00
def start_cluster ( ) :
try :
cluster . start ( )
yield cluster
finally :
cluster . shutdown ( )
2022-03-22 16:39:58 +00:00
2022-05-27 16:30:29 +00:00
TEST_QUERY_A = " SELECT number FROM numbers(1000) GROUP BY number SETTINGS memory_overcommit_ratio_denominator_for_user=1, memory_usage_overcommit_max_wait_microseconds=500 "
TEST_QUERY_B = " SELECT number FROM numbers(1000) GROUP BY number SETTINGS memory_overcommit_ratio_denominator_for_user=2, memory_usage_overcommit_max_wait_microseconds=500 "
2022-03-22 16:39:58 +00:00
2022-02-15 00:29:55 +00:00
def test_overcommited_is_killed ( ) :
node . query ( " CREATE USER A " )
node . query ( " GRANT ALL ON *.* TO A " )
node . query ( " CREATE USER B " )
node . query ( " GRANT ALL ON *.* TO B " )
responses_A = list ( )
responses_B = list ( )
2022-03-29 13:09:37 +00:00
for _ in range ( 500 ) :
2022-02-15 00:29:55 +00:00
responses_A . append ( node . get_query_request ( TEST_QUERY_A , user = " A " ) )
responses_B . append ( node . get_query_request ( TEST_QUERY_B , user = " B " ) )
overcommited_killed = False
for response in responses_A :
_ , err = response . get_answer_and_error ( )
if " MEMORY_LIMIT_EXCEEDED " in err :
overcommited_killed = True
finished = False
for response in responses_B :
_ , err = response . get_answer_and_error ( )
if err == " " :
finished = True
2022-03-22 16:39:58 +00:00
assert (
2022-05-27 16:30:29 +00:00
overcommited_killed
) , " no overcommited task was killed "
assert (
finished
) , " all tasks are killed "
2022-02-15 00:29:55 +00:00
node . query ( " DROP USER IF EXISTS A " )
node . query ( " DROP USER IF EXISTS B " )