Skip to content

Commit d83bd14

Browse files
committed
fix(dbhelper): stabilize binlog metadata and userstats test
1 parent 5ab3026 commit d83bd14

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

utils/dbhelper/status_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,20 @@ func TestGetCPUUsageFromUserStats_Integration(t *testing.T) {
399399
t.Skip("USER_STATISTICS only available on MariaDB")
400400
}
401401

402+
// Ensure user statistics are enabled for this integration test.
403+
if _, err := db.Exec("SET GLOBAL userstat = 1"); err != nil {
404+
if strings.Contains(err.Error(), "Access denied") || strings.Contains(err.Error(), "SUPER") {
405+
t.Skip("userstat requires elevated privileges")
406+
}
407+
t.Fatalf("SET GLOBAL userstat=1 failed: %v", err)
408+
}
409+
410+
// Generate a bit of activity so USER_STATISTICS has a row.
411+
var dummy int
412+
if err := db.QueryRow("SELECT 1").Scan(&dummy); err != nil {
413+
t.Fatalf("failed to generate user activity: %v", err)
414+
}
415+
402416
value, query, err := GetCPUUsageFromUserStats(db)
403417
if err != nil {
404418
// USER_STATISTICS might not be enabled

utils/dbhelper/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ func (m *BinaryLogMetaMap) MarshalIndent(prefix, indent string) ([]byte, error)
850850

851851
// ClearObsoleteMetadata removes entries older than the specified binlog file
852852
func (m *BinaryLogMetaMap) ClearObsoleteMetadata(oldest string) (deleted []string) {
853+
deleted = make([]string, 0)
853854
keys := make([]string, 0)
854855
m.Range(func(k, v any) bool {
855856
keys = append(keys, k.(string))

0 commit comments

Comments
 (0)