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
@@ -410,3 +410,93 @@ func TestDeleteIPsAndClearQueue(t *testing.T) {
|
||||
t.Fatalf("expected validator freed after clear, got state=%s current_ip=%v", v.State, v.CurrentIPID)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOrchestratorSettingsGetPut proves the settle-delay setting round-trips
|
||||
// through GET/PUT /api/v1/admin/config/orchestrator.
|
||||
func TestOrchestratorSettingsGetPut(t *testing.T) {
|
||||
fc, _, _, _ := newConfigTestHarness(t)
|
||||
|
||||
resp, body := fc.do(http.MethodGet, "/api/v1/admin/config/orchestrator", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("get settings: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
var got orchestratorSettingsDTO
|
||||
if err := json.Unmarshal(body, &got); err != nil {
|
||||
t.Fatalf("unmarshal get response: %v", err)
|
||||
}
|
||||
if got.FIPSettleSeconds != 0 {
|
||||
t.Fatalf("expected default 0, got %+v", got)
|
||||
}
|
||||
|
||||
resp, body = fc.do(http.MethodPut, "/api/v1/admin/config/orchestrator", orchestratorSettingsDTO{FIPSettleSeconds: 20})
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("put settings: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
if err := json.Unmarshal(body, &got); err != nil {
|
||||
t.Fatalf("unmarshal put response: %v", err)
|
||||
}
|
||||
if got.FIPSettleSeconds != 20 {
|
||||
t.Fatalf("expected 20, got %+v", got)
|
||||
}
|
||||
|
||||
resp, body = fc.do(http.MethodGet, "/api/v1/admin/config/orchestrator", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("get settings after put: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
if err := json.Unmarshal(body, &got); err != nil {
|
||||
t.Fatalf("unmarshal get-after-put response: %v", err)
|
||||
}
|
||||
if got.FIPSettleSeconds != 20 {
|
||||
t.Fatalf("expected 20 to persist, got %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOrchestratorSettingsPutValidation proves a value that would leave no
|
||||
// room for self-check inside the claim lease is rejected with 400.
|
||||
func TestOrchestratorSettingsPutValidation(t *testing.T) {
|
||||
fc, _, _, _ := newConfigTestHarness(t)
|
||||
// newConfigTestHarness: LeaseTTLSeconds=180, SelfCheckTimeoutSeconds=10.
|
||||
|
||||
resp, body := fc.do(http.MethodPut, "/api/v1/admin/config/orchestrator", orchestratorSettingsDTO{FIPSettleSeconds: 175})
|
||||
if resp.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("expected 400 for settle seconds too close to lease ttl, status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
resp, body = fc.do(http.MethodPut, "/api/v1/admin/config/orchestrator", orchestratorSettingsDTO{FIPSettleSeconds: -1})
|
||||
if resp.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("expected 400 for negative settle seconds, status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFIPSettleDelayGatesAssignmentEndpoint proves GET
|
||||
// /api/v1/agents/{id}/assignment returns 204 while the settle window is
|
||||
// open and 200 once it has elapsed — the end-to-end proof of the whole
|
||||
// feature over the real HTTP wire contract.
|
||||
func TestFIPSettleDelayGatesAssignmentEndpoint(t *testing.T) {
|
||||
fc, _, orch, mock := newConfigTestHarness(t)
|
||||
ctx := context.Background()
|
||||
mock.Seed("fip-1", "9.9.9.9", "svc-project")
|
||||
|
||||
resp, body := fc.do(http.MethodPut, "/api/v1/admin/config/orchestrator", orchestratorSettingsDTO{FIPSettleSeconds: 1})
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("put settings: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
fc.do(http.MethodPost, "/api/v1/admin/config/validators", createValidatorRequest{ValidatorID: "validator-1", OSPortID: "port-1"})
|
||||
fc.do(http.MethodPost, "/api/v1/agents/register", registerAgentRequest{ValidatorID: "validator-1"})
|
||||
fc.do(http.MethodPost, "/api/v1/admin/ips", submitIPsRequest{Addresses: []string{"9.9.9.9"}})
|
||||
|
||||
orch.Tick(ctx) // claim + associate -> awaiting_self_check, fip attached
|
||||
|
||||
resp, body = fc.do(http.MethodGet, "/api/v1/agents/validator-1/assignment", nil)
|
||||
if resp.StatusCode != http.StatusNoContent {
|
||||
t.Fatalf("expected 204 during settle window, status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
time.Sleep(1100 * time.Millisecond)
|
||||
|
||||
resp, body = fc.do(http.MethodGet, "/api/v1/agents/validator-1/assignment", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("expected 200 after settle window elapsed, status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user