Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit acd2bb1

Browse files
fix: minor fixes in reconciliation loop
1 parent 8723fe9 commit acd2bb1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

coderd/prebuilds/preset_snapshot.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ func (p PresetSnapshot) CalculateState() *ReconciliationState {
9191
extraneous int32
9292
)
9393

94+
// #nosec G115 - Safe conversion as p.Running slice length is expected to be within int32 range
95+
actual = int32(len(p.Running))
96+
9497
if p.isActive() {
95-
// #nosec G115 - Safe conversion as p.Running slice length is expected to be within int32 range
96-
actual = int32(len(p.Running))
9798
desired = p.Preset.DesiredInstances.Int32
9899
eligible = p.countEligible()
99100
extraneous = max(actual-desired, 0)

coderd/prebuilds/preset_snapshot_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ func TestOutdatedPrebuilds(t *testing.T) {
146146
state := ps.CalculateState()
147147
actions, err := ps.CalculateActions(clock, backoffInterval)
148148
require.NoError(t, err)
149-
validateState(t, prebuilds.ReconciliationState{}, *state)
149+
validateState(t, prebuilds.ReconciliationState{
150+
Actual: 1,
151+
}, *state)
150152
validateActions(t, prebuilds.ReconciliationActions{
151153
ActionType: prebuilds.ActionTypeDelete,
152154
DeleteIDs: []uuid.UUID{outdated.prebuiltWorkspaceID},
@@ -208,6 +210,7 @@ func TestDeleteOutdatedPrebuilds(t *testing.T) {
208210
actions, err := ps.CalculateActions(clock, backoffInterval)
209211
require.NoError(t, err)
210212
validateState(t, prebuilds.ReconciliationState{
213+
Actual: 1,
211214
Deleting: 1,
212215
}, *state)
213216

@@ -530,7 +533,9 @@ func TestDeprecated(t *testing.T) {
530533
state := ps.CalculateState()
531534
actions, err := ps.CalculateActions(clock, backoffInterval)
532535
require.NoError(t, err)
533-
validateState(t, prebuilds.ReconciliationState{}, *state)
536+
validateState(t, prebuilds.ReconciliationState{
537+
Actual: 1,
538+
}, *state)
534539
validateActions(t, prebuilds.ReconciliationActions{
535540
ActionType: prebuilds.ActionTypeDelete,
536541
DeleteIDs: []uuid.UUID{current.prebuiltWorkspaceID},

0 commit comments

Comments
 (0)