added FIP Cooldown before start
This commit is contained in:
1 parent
291eea3eb8
commit
f22ad569b6
36 files changed
+1182
-25
No files matched your search
@@ -409,6 +409,124 @@ func TestClearQueueDisassociatesAllFIPs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestFIPSettleDelayWithholdsAssignment proves a nonzero fip_settle_seconds
|
||||
// keeps AssignmentForValidator returning nil (agent keeps polling and
|
||||
// getting nothing) until the configured pause has elapsed since the
|
||||
// floating IP was associated.
|
||||
func TestFIPSettleDelayWithholdsAssignment(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
o, d, mock := newTestOrchestrator(t, 180)
|
||||
if err := o.SetFIPSettleSeconds(ctx, 1); err != nil {
|
||||
t.Fatalf("set fip settle seconds: %v", err)
|
||||
}
|
||||
mock.Seed("fip-1", "1.2.3.4", "svc-project")
|
||||
_ = d.RegisterValidator(ctx, "validator-1", "host-1", "port-1", "v0.1")
|
||||
_ = d.SeedQueue(ctx, []string{"1.2.3.4"})
|
||||
|
||||
o.Tick(ctx) // claim + associate -> awaiting_self_check, fip attached
|
||||
|
||||
item, checks, err := o.AssignmentForValidator(ctx, "validator-1")
|
||||
if err != nil {
|
||||
t.Fatalf("assignment for validator: %v", err)
|
||||
}
|
||||
if item != nil || checks != nil {
|
||||
t.Fatalf("expected no assignment during settle window, got item=%+v checks=%+v", item, checks)
|
||||
}
|
||||
|
||||
time.Sleep(1100 * time.Millisecond)
|
||||
|
||||
item, checks, err = o.AssignmentForValidator(ctx, "validator-1")
|
||||
if err != nil {
|
||||
t.Fatalf("assignment for validator after settle: %v", err)
|
||||
}
|
||||
if item == nil {
|
||||
t.Fatalf("expected assignment to be available once settle window elapsed")
|
||||
}
|
||||
if len(checks) == 0 {
|
||||
t.Fatalf("expected check config to be returned alongside the item")
|
||||
}
|
||||
}
|
||||
|
||||
// TestFIPSettleDelayZeroIsNoOp proves the default fip_settle_seconds=0
|
||||
// never withholds an assignment — no behavior change for upgraded-but-
|
||||
// unconfigured installs.
|
||||
func TestFIPSettleDelayZeroIsNoOp(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
o, d, mock := newTestOrchestrator(t, 180)
|
||||
mock.Seed("fip-1", "1.2.3.4", "svc-project")
|
||||
_ = d.RegisterValidator(ctx, "validator-1", "host-1", "port-1", "v0.1")
|
||||
_ = d.SeedQueue(ctx, []string{"1.2.3.4"})
|
||||
|
||||
o.Tick(ctx)
|
||||
|
||||
item, _, err := o.AssignmentForValidator(ctx, "validator-1")
|
||||
if err != nil {
|
||||
t.Fatalf("assignment for validator: %v", err)
|
||||
}
|
||||
if item == nil {
|
||||
t.Fatalf("expected assignment immediately available with fip_settle_seconds=0")
|
||||
}
|
||||
}
|
||||
|
||||
// TestFIPSettleDelayIgnoresNilFIPAssociatedAt proves an in-flight row from
|
||||
// before this feature's migration (fip_associated_at NULL) is never newly
|
||||
// blocked, even with a nonzero configured pause — upgrading control-api
|
||||
// must not strand an address already awaiting self-check.
|
||||
func TestFIPSettleDelayIgnoresNilFIPAssociatedAt(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
o, d, mock := newTestOrchestrator(t, 180)
|
||||
if err := o.SetFIPSettleSeconds(ctx, 60); err != nil {
|
||||
t.Fatalf("set fip settle seconds: %v", err)
|
||||
}
|
||||
mock.Seed("fip-1", "1.2.3.4", "svc-project")
|
||||
_ = d.RegisterValidator(ctx, "validator-1", "host-1", "port-1", "v0.1")
|
||||
_ = d.SeedQueue(ctx, []string{"1.2.3.4"})
|
||||
|
||||
o.Tick(ctx)
|
||||
|
||||
item, err := d.GetIPByAddress(ctx, "1.2.3.4")
|
||||
if err != nil {
|
||||
t.Fatalf("get ip: %v", err)
|
||||
}
|
||||
if _, err := d.ExecContext(ctx, `UPDATE ip_queue SET fip_associated_at=NULL WHERE id=?`, item.ID); err != nil {
|
||||
t.Fatalf("clear fip_associated_at: %v", err)
|
||||
}
|
||||
|
||||
assigned, _, err := o.AssignmentForValidator(ctx, "validator-1")
|
||||
if err != nil {
|
||||
t.Fatalf("assignment for validator: %v", err)
|
||||
}
|
||||
if assigned == nil {
|
||||
t.Fatalf("expected assignment available for a row with nil FIPAssociatedAt despite nonzero settle delay")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetFIPSettleSecondsValidation proves the cross-field rule against
|
||||
// lease_ttl_seconds/self_check_timeout_seconds is enforced.
|
||||
func TestSetFIPSettleSecondsValidation(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
o, _, _ := newTestOrchestrator(t, 180) // SelfCheckTimeoutSeconds: 10 (see newTestOrchestratorWithSites)
|
||||
|
||||
cases := []struct {
|
||||
seconds int
|
||||
wantErr bool
|
||||
}{
|
||||
{-1, true},
|
||||
{170, true}, // 170+10 >= 180
|
||||
{169, false},
|
||||
{0, false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
err := o.SetFIPSettleSeconds(ctx, c.seconds)
|
||||
if c.wantErr && !errors.Is(err, db.ErrValidation) {
|
||||
t.Errorf("seconds=%d: expected ErrValidation, got %v", c.seconds, err)
|
||||
}
|
||||
if !c.wantErr && err != nil {
|
||||
t.Errorf("seconds=%d: expected success, got %v", c.seconds, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestInboundChecksPartialSites confirms a partially-configured sites list
|
||||
// (fewer than 3 slots assigned) only waits on the sites actually
|
||||
// configured — the two unassigned slots are never expected.
|
||||
|
||||
Reference in new issue
Block a user