A new template version is created with a preset with prebuilds configured; this outdates the older version and requires the old prebuilds to be destroyed and new prebuilds to be created.
(t *testing.T)
| 128 | // A new template version is created with a preset with prebuilds configured; this outdates the older version and |
| 129 | // requires the old prebuilds to be destroyed and new prebuilds to be created. |
| 130 | func TestOutdatedPrebuilds(t *testing.T) { |
| 131 | t.Parallel() |
| 132 | outdated := opts[optionSet0] |
| 133 | current := opts[optionSet1] |
| 134 | clock := quartz.NewMock(t) |
| 135 | |
| 136 | // GIVEN: 2 presets, one outdated and one new. |
| 137 | presets := []database.GetTemplatePresetsWithPrebuildsRow{ |
| 138 | preset(false, 1, outdated), |
| 139 | preset(true, 1, current), |
| 140 | } |
| 141 | |
| 142 | // GIVEN: a running prebuild for the outdated preset. |
| 143 | running := []database.GetRunningPrebuiltWorkspacesRow{ |
| 144 | prebuiltWorkspace(outdated, clock), |
| 145 | } |
| 146 | |
| 147 | // GIVEN: no in-progress builds. |
| 148 | var inProgress []database.CountInProgressPrebuildsRow |
| 149 | |
| 150 | // WHEN: calculating the outdated preset's state. |
| 151 | snapshot := prebuilds.NewGlobalSnapshot(presets, nil, running, inProgress, nil, nil, nil, quartz.NewMock(t), testutil.Logger(t)) |
| 152 | ps, err := snapshot.FilterByPreset(outdated.presetID) |
| 153 | require.NoError(t, err) |
| 154 | |
| 155 | // THEN: we should identify that this prebuild is outdated and needs to be deleted. |
| 156 | state := ps.CalculateState() |
| 157 | actions, err := ps.CalculateActions(backoffInterval) |
| 158 | require.NoError(t, err) |
| 159 | validateState(t, prebuilds.ReconciliationState{ |
| 160 | Actual: 1, |
| 161 | }, *state) |
| 162 | validateActions(t, []*prebuilds.ReconciliationActions{ |
| 163 | { |
| 164 | ActionType: prebuilds.ActionTypeDelete, |
| 165 | DeleteIDs: []uuid.UUID{outdated.prebuiltWorkspaceID}, |
| 166 | }, |
| 167 | }, actions) |
| 168 | |
| 169 | // WHEN: calculating the current preset's state. |
| 170 | ps, err = snapshot.FilterByPreset(current.presetID) |
| 171 | require.NoError(t, err) |
| 172 | |
| 173 | // THEN: we should not be blocked from creating a new prebuild while the outdate one deletes. |
| 174 | state = ps.CalculateState() |
| 175 | actions, err = ps.CalculateActions(backoffInterval) |
| 176 | require.NoError(t, err) |
| 177 | validateState(t, prebuilds.ReconciliationState{Desired: 1}, *state) |
| 178 | validateActions(t, []*prebuilds.ReconciliationActions{ |
| 179 | { |
| 180 | ActionType: prebuilds.ActionTypeCreate, |
| 181 | Create: 1, |
| 182 | }, |
| 183 | }, actions) |
| 184 | } |
| 185 | |
| 186 | // Make sure that outdated prebuild will be deleted, even if deletion of another outdated prebuild is already in progress. |
| 187 | func TestDeleteOutdatedPrebuilds(t *testing.T) { |
nothing calls this directly
no test coverage detected