MCPcopy Create free account
hub / github.com/coder/coder / TestDeleteOutdatedPrebuilds

Function TestDeleteOutdatedPrebuilds

coderd/prebuilds/preset_snapshot_test.go:187–237  ·  view source on GitHub ↗

Make sure that outdated prebuild will be deleted, even if deletion of another outdated prebuild is already in progress.

(t *testing.T)

Source from the content-addressed store, hash-verified

185
186// Make sure that outdated prebuild will be deleted, even if deletion of another outdated prebuild is already in progress.
187func 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
239func TestCancelPendingPrebuilds(t *testing.T) {
240 t.Parallel()

Callers

nothing calls this directly

Calls 9

FilterByPresetMethod · 0.95
NewGlobalSnapshotFunction · 0.92
LoggerFunction · 0.92
presetFunction · 0.85
prebuiltWorkspaceFunction · 0.85
validateStateFunction · 0.85
validateActionsFunction · 0.85
CalculateStateMethod · 0.80
CalculateActionsMethod · 0.45

Tested by

no test coverage detected