Files
seaweedfs/weed/admin/dash/ec_balancer_overlap_test.go
T
Chris LuandClaude Opus 5.5 413fdf1968 admin: list the EC balancers that are active at the same time
The plugin ec_balance job, the legacy maintenance manager's ec_balance task
and an admin_script job that runs ec.balance -apply each plan shard moves
from the same topology without knowing about the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:33:28 -08:00

53 lines
1.9 KiB
Go

package dash
import (
"reflect"
"testing"
)
func TestScriptAppliesECBalance(t *testing.T) {
cases := []struct {
script string
want bool
}{
{"", false},
{"fs.log.purge -daysAgo=7\nvolume.fix.replication -apply", false},
{"ec.balance", false},
{"ec.balance -collection=x", false},
{"ec.balance -apply", true},
{"ec.balance -force", true},
{"ec.balance --apply", true},
{"ec.balance -apply=true", true},
{"ec.balance -apply=false", false},
{"# ec.balance -apply", false},
{"volume.list; ec.balance -collection=a -apply", true},
{"ec.rebuild -apply\r\nec.balance -apply\r\n", true},
{"ec.balancer -apply", false},
}
for _, c := range cases {
if got := scriptAppliesECBalance(c.script); got != c.want {
t.Errorf("scriptAppliesECBalance(%q) = %v, want %v", c.script, got, c.want)
}
}
}
func TestActiveECBalancers(t *testing.T) {
cases := []struct {
name string
state ecBalancerState
want []string
}{
{"none", ecBalancerState{}, nil},
{"plugin only", ecBalancerState{PluginECBalanceEnabled: true}, []string{ecBalancerPlugin}},
{"disabled script ignored", ecBalancerState{PluginECBalanceEnabled: true, AdminScript: "ec.balance -apply"}, []string{ecBalancerPlugin}},
{"script without ec.balance", ecBalancerState{PluginECBalanceEnabled: true, AdminScriptEnabled: true, AdminScript: "volume.fix.replication -apply"}, []string{ecBalancerPlugin}},
{"all three", ecBalancerState{PluginECBalanceEnabled: true, LegacyECBalanceEnabled: true, AdminScriptEnabled: true, AdminScript: "ec.balance -apply"}, []string{ecBalancerPlugin, ecBalancerLegacy, ecBalancerAdminScript}},
{"legacy and script", ecBalancerState{LegacyECBalanceEnabled: true, AdminScriptEnabled: true, AdminScript: "ec.balance -force"}, []string{ecBalancerLegacy, ecBalancerAdminScript}},
}
for _, c := range cases {
if got := activeECBalancers(c.state); !reflect.DeepEqual(got, c.want) {
t.Errorf("%s: activeECBalancers = %v, want %v", c.name, got, c.want)
}
}
}