Make sure that outdated prebuild will be deleted, even if deletion of another outdated prebuild is already in progress.
(t *testing.T)
| 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) { |
| 188 | t.Parallel() |
| 189 | outdated := opts[optionSet0] |
| 190 | clock := quartz.NewMock(t) |
| 191 | |
| 192 | // GIVEN: 1 outdated preset. |
| 193 | presets := []database.GetTemplatePresetsWithPrebuildsRow{ |
| 194 | preset(false, 1, outdated), |
| 195 | } |
| 196 | |
| 197 | // GIVEN: one running prebuild for the outdated preset. |
| 198 | running := []database.GetRunningPrebuiltWorkspacesRow{ |
| 199 | prebuiltWorkspace(outdated, clock), |
| 200 | } |
| 201 | |
| 202 | // GIVEN: one deleting prebuild for the outdated preset. |
| 203 | inProgress := []database.CountInProgressPrebuildsRow{ |
| 204 | { |
| 205 | TemplateID: outdated.templateID, |
| 206 | TemplateVersionID: outdated.templateVersionID, |
| 207 | Transition: database.WorkspaceTransitionDelete, |
| 208 | Count: 1, |
| 209 | PresetID: uuid.NullUUID{ |
| 210 | UUID: outdated.presetID, |
| 211 | Valid: true, |
| 212 | }, |
| 213 | }, |
| 214 | } |
| 215 | |
| 216 | // WHEN: calculating the outdated preset's state. |
| 217 | snapshot := prebuilds.NewGlobalSnapshot(presets, nil, running, inProgress, nil, nil, nil, quartz.NewMock(t), testutil.Logger(t)) |
| 218 | ps, err := snapshot.FilterByPreset(outdated.presetID) |
| 219 | require.NoError(t, err) |
| 220 | |
| 221 | // THEN: we should identify that this prebuild is outdated and needs to be deleted. |
| 222 | // Despite the fact that deletion of another outdated prebuild is already in progress. |
| 223 | state := ps.CalculateState() |
| 224 | actions, err := ps.CalculateActions(backoffInterval) |
| 225 | require.NoError(t, err) |
| 226 | validateState(t, prebuilds.ReconciliationState{ |
| 227 | Actual: 1, |
| 228 | Deleting: 1, |
| 229 | }, *state) |
| 230 | |
| 231 | validateActions(t, []*prebuilds.ReconciliationActions{ |
| 232 | { |
| 233 | ActionType: prebuilds.ActionTypeDelete, |
| 234 | DeleteIDs: []uuid.UUID{outdated.prebuiltWorkspaceID}, |
| 235 | }, |
| 236 | }, actions) |
| 237 | } |
| 238 | |
| 239 | func TestCancelPendingPrebuilds(t *testing.T) { |
| 240 | t.Parallel() |
nothing calls this directly
no test coverage detected