@@ -62,15 +62,15 @@ def started_cluster():
6262 cluster .shutdown ()
6363
6464
65- def get_memory_usage_from_client_output_and_close (client_output ):
65+ def get_memory_usage_from_client_output_and_close (client_output , shard_name ):
6666 client_output .seek (0 )
6767 client_memory_value = None
6868 server_memory_value = None
6969 peak_memory_usage_found = False
7070
7171 for line in client_output :
72- # Peak memory usage should be on shard_2
73- if server_memory_value is None and "shard_2" in line :
72+ # Peak memory usage should be on the specified shard
73+ if server_memory_value is None and shard_name in line :
7474 server_match = re .search (r"Query peak memory usage: ([0-9.]+)" , line )
7575 if server_match :
7676 server_memory_value = float (server_match .group (1 ))
@@ -88,6 +88,10 @@ def get_memory_usage_from_client_output_and_close(client_output):
8888 peak_memory_usage_found = False
8989
9090 client_output .close ()
91+
92+ assert client_memory_value is not None , "Client peak memory usage not found"
93+ assert server_memory_value is not None , "Server peak memory usage not found"
94+
9195 return client_memory_value , server_memory_value
9296
9397
@@ -104,10 +108,7 @@ def test_clickhouse_client_max_peak_memory_usage_distributed(started_cluster):
104108 client1 .expect ("Peak memory usage" , timeout = 60 )
105109 client1 .expect (prompt )
106110
107- client_memory_value , server_memory_value = get_memory_usage_from_client_output_and_close (client_output )
108-
109- assert client_memory_value is not None , "Client peak memory usage not found"
110- assert server_memory_value is not None , "Server peak memory usage not found"
111+ client_memory_value , server_memory_value = get_memory_usage_from_client_output_and_close (client_output , "shard_2" )
111112
112113 # Assert difference is less than 1 MB
113114 memory_diff = abs (client_memory_value - server_memory_value )
@@ -128,10 +129,7 @@ def test_clickhouse_client_max_peak_memory_single_node(started_cluster):
128129 client1 .expect ("Peak memory usage" , timeout = 60 )
129130 client1 .expect (prompt )
130131
131- client_memory_value , server_memory_value = get_memory_usage_from_client_output_and_close (client_output )
132-
133- assert client_memory_value is not None , "Client peak memory usage not found"
134- assert server_memory_value is not None , "Server peak memory usage not found"
132+ client_memory_value , server_memory_value = get_memory_usage_from_client_output_and_close (client_output , "shard_1" )
135133
136134 # Assert difference is less than 1 MB
137135 memory_diff = abs (client_memory_value - server_memory_value )
0 commit comments