This is an automated email from the ASF dual-hosted git repository.

tuhaihe pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 3fad47560e15e6be3a6a27780cacf5790eb0ec04
Author: liushengsong <[email protected]>
AuthorDate: Thu Jun 18 11:16:59 2026 +0800

    Fix flaky resgroup_cpu_max_percent: average all CPU samples
    
    verify_cpu_usage() only used the first sample (all_info[0]) instead of
    averaging all collected samples, making it sensitive to single-sample
    fluctuations on busy CI machines. Use the mean of all samples as the
    function comment originally intended.
---
 .../test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out    | 4 ++--
 .../src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql     | 3 +--
 src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out    | 4 ++--
 src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql         | 3 +--
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git 
a/contrib/pax_storage/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out
 
b/contrib/pax_storage/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out
index ae21059fcb6..1e011ecec22 100644
--- 
a/contrib/pax_storage/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out
+++ 
b/contrib/pax_storage/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out
@@ -33,8 +33,8 @@ CREATE
 -- verify_cpu_usage: calculate each QE's average cpu usage using all the data 
in
 -- the table cpu_usage_sample. And compare the average value to the expected 
value.
 -- return true if the practical value is close to the expected value.
-CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage 
INT, err_rate INT) RETURNS BOOL AS $$ import json import functools 
-all_info = plpy.execute(''' SELECT sample::json->'{name}' AS cpu FROM 
cpu_usage_samples '''.format(name=groupname)) usage = float(all_info[0]['cpu']) 
+CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage 
INT, err_rate INT) RETURNS BOOL AS $$ import json 
+all_info = plpy.execute(''' SELECT sample::json->'{name}' AS cpu FROM 
cpu_usage_samples '''.format(name=groupname)) usage = sum(float(row['cpu']) for 
row in all_info) / len(all_info) 
 return abs(usage - expect_cpu_usage) <= err_rate $$ LANGUAGE plpython3u;
 CREATE
 
diff --git 
a/contrib/pax_storage/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql
 
b/contrib/pax_storage/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql
index 14220c38a42..a014108bb52 100644
--- 
a/contrib/pax_storage/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql
+++ 
b/contrib/pax_storage/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql
@@ -38,12 +38,11 @@ $$ LANGUAGE plpython3u;
 CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage 
INT, err_rate INT)
 RETURNS BOOL AS $$
     import json
-    import functools
 
     all_info = plpy.execute('''
         SELECT sample::json->'{name}' AS cpu FROM cpu_usage_samples
     '''.format(name=groupname))
-    usage = float(all_info[0]['cpu'])
+    usage = sum(float(row['cpu']) for row in all_info) / len(all_info)
 
     return abs(usage - expect_cpu_usage) <= err_rate
 $$ LANGUAGE plpython3u;
diff --git a/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out 
b/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out
index 2e7b32f1d74..44969ba7eea 100644
--- a/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out
+++ b/src/test/isolation2/expected/resgroup/resgroup_cpu_max_percent.out
@@ -33,8 +33,8 @@ CREATE
 -- verify_cpu_usage: calculate each QE's average cpu usage using all the data 
in
 -- the table cpu_usage_sample. And compare the average value to the expected 
value.
 -- return true if the practical value is close to the expected value.
-CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage 
INT, err_rate INT) RETURNS BOOL AS $$ import json import functools 
-all_info = plpy.execute(''' SELECT sample::json->'{name}' AS cpu FROM 
cpu_usage_samples '''.format(name=groupname)) usage = float(all_info[0]['cpu']) 
+CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage 
INT, err_rate INT) RETURNS BOOL AS $$ import json 
+all_info = plpy.execute(''' SELECT sample::json->'{name}' AS cpu FROM 
cpu_usage_samples '''.format(name=groupname)) usage = sum(float(row['cpu']) for 
row in all_info) / len(all_info) 
 return abs(usage - expect_cpu_usage) <= err_rate $$ LANGUAGE plpython3u;
 CREATE
 
diff --git a/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql 
b/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql
index c7dfc9f60b0..89fa523cc88 100644
--- a/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql
+++ b/src/test/isolation2/sql/resgroup/resgroup_cpu_max_percent.sql
@@ -38,12 +38,11 @@ $$ LANGUAGE plpython3u;
 CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage 
INT, err_rate INT)
 RETURNS BOOL AS $$
     import json
-    import functools
 
     all_info = plpy.execute('''
         SELECT sample::json->'{name}' AS cpu FROM cpu_usage_samples
     '''.format(name=groupname))
-    usage = float(all_info[0]['cpu'])
+    usage = sum(float(row['cpu']) for row in all_info) / len(all_info)
 
     return abs(usage - expect_cpu_usage) <= err_rate
 $$ LANGUAGE plpython3u;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to