Files
minio/cmd/bucket-replication-metrics_test.go
T
Feng Ruohang 099b7ddf37 fix(replication): handle absent pool in worker metrics
Signed-off-by: Feng Ruohang <rh@vonng.com>
2026-11-09 18:10:19 +08:00

33 lines
1016 B
Go

// Copyright (c) 2026 PGSTY
// SPDX-License-Identifier: AGPL-3.0-only
package cmd
import (
"testing"
"github.com/minio/minio/internal/once"
"github.com/rcrowley/go-metrics"
)
func TestReplicationWorkerMetricsWithoutPool(t *testing.T) {
previous := globalReplicationPool
t.Cleanup(func() { globalReplicationPool = previous })
globalReplicationPool = once.NewSingleton[ReplicationPool]()
globalReplicationPool.Set(&ReplicationPool{activeWorkers: 8})
stat := newActiveWorkerStat(metrics.NewRegistry())
stat.update()
if got := stat.get(); got.Curr != 8 || got.Avg != 8 || got.Max != 8 {
t.Fatalf("active pool metrics = %+v, want current/average/maximum 8", got)
}
// A collector may still run after replication has been disabled.
globalReplicationPool = once.NewSingleton[ReplicationPool]()
globalReplicationPool.Set(nil)
stat.update()
if got := stat.get(); got.Curr != 0 || got.Avg != 4 || got.Max != 8 {
t.Fatalf("disabled pool metrics = %+v, want current 0, average 4, maximum 8", got)
}
}