Skip to content

Commit d01f41e

Browse files
func: update integration handler tests
1 parent c0ebf91 commit d01f41e

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

policy/handler.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,17 @@ func NewPolicyHandler(config HandlerConfig) (*Handler, error) {
173173
}
174174

175175
func (h *Handler) configureHorizontalPolicy() error {
176+
return h.updateHorizontalPolicy(h.policy)
177+
}
176178

179+
func (h *Handler) updateHorizontalPolicy(up *sdk.ScalingPolicy) error {
177180
err := h.loadCheckRunners()
178181
if err != nil {
179182
return fmt.Errorf("failed to load check handlers: %w", err)
180183
}
181184

182-
h.minCount = h.policy.Min
183-
h.maxCount = h.policy.Max
185+
h.minCount = up.Min
186+
h.maxCount = up.Max
184187

185188
h.calculateNewCount = h.calculateHorizontalNewCount
186189
return nil
@@ -211,6 +214,7 @@ func (h *Handler) loadCheckRunners() error {
211214
runners = append(runners, runner)
212215
}
213216

217+
// Do the update as a single operation to avoid partial updates.
214218
h.checkRunners = runners
215219
return nil
216220
}
@@ -397,24 +401,22 @@ func (h *Handler) updateHandler(updatedPolicy *sdk.ScalingPolicy) {
397401

398402
switch updatedPolicy.Type {
399403
case sdk.ScalingPolicyTypeCluster, sdk.ScalingPolicyTypeHorizontal:
400-
h.log.Debug("updating check handlers", "old_checks", len(h.policy.Checks),
401-
"new_checks", len(updatedPolicy.Checks))
402-
err := h.configureHorizontalPolicy()
404+
err := h.updateHorizontalPolicy(updatedPolicy)
403405
if err != nil {
404-
h.errChn <- fmt.Errorf("unable to update horizontal policy: %w", err)
406+
h.errChn <- fmt.Errorf("unable to update horizontal policy %w", err)
405407
return
406408
}
407409

408410
default:
409-
err := h.configureVerticalPolicy()
411+
err := h.updateVerticalPolicy(updatedPolicy)
410412
if err != nil {
411-
h.errChn <- fmt.Errorf("unable to update vertical policy: %w", err)
413+
h.errChn <- fmt.Errorf("unable to update vertical policy %w", err)
414+
return
412415
}
413416
}
414417

415-
h.log.Debug("policy successfully updated")
416418
h.policy = updatedPolicy
417-
419+
h.log.Debug("policy successfully updated")
418420
}
419421

420422
// applyMutators applies the mutators registered with the handler in order and

policy/handler_oss.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ func (h *Handler) configureVerticalPolicy() error {
2222
}
2323
return nil
2424
}
25+
26+
func (h *Handler) updateVerticalPolicy(up *sdk.ScalingPolicy) error {
27+
return h.configureVerticalPolicy()
28+
}

policy/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func TestHandler_Run_ScalingNotNeeded_Integration(t *testing.T) {
467467
pm: mdg,
468468
}
469469

470-
must.NoError(t, handler.loadCheckRunners())
470+
must.NoError(t, handler.configureHorizontalPolicy())
471471

472472
go handler.Run(ctx)
473473
time.Sleep(30 * time.Millisecond)

0 commit comments

Comments
 (0)