MCPcopy Index your code
hub / github.com/coder/coder / TestTemplateUpdatePrebuilds

Function TestTemplateUpdatePrebuilds

enterprise/coderd/schedule/template_test.go:1144–1386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1142}
1143
1144func TestTemplateUpdatePrebuilds(t *testing.T) {
1145 t.Parallel()
1146
1147 // Dormant auto-delete configured to 10 hours
1148 dormantAutoDelete := 10 * time.Hour
1149
1150 // TTL configured to 8 hours
1151 ttl := 8 * time.Hour
1152
1153 // Autostop configuration set to everyday at midnight
1154 autostopWeekdays, err := codersdk.WeekdaysToBitmap(codersdk.AllDaysOfWeek)
1155 require.NoError(t, err)
1156
1157 // Autostart configuration set to everyday at midnight
1158 autostartSchedule, err := cron.Weekly("CRON_TZ=UTC 0 0 * * *")
1159 require.NoError(t, err)
1160 autostartWeekdays, err := codersdk.WeekdaysToBitmap(codersdk.AllDaysOfWeek)
1161 require.NoError(t, err)
1162
1163 cases := []struct {
1164 name string
1165 templateSchedule agplschedule.TemplateScheduleOptions
1166 workspaceUpdate func(*testing.T, context.Context, database.Store, time.Time, database.ClaimPrebuiltWorkspaceRow)
1167 assertWorkspace func(*testing.T, context.Context, database.Store, time.Time, bool, database.Workspace)
1168 }{
1169 {
1170 name: "TemplateDormantAutoDeleteUpdatePrebuildAfterClaim",
1171 templateSchedule: agplschedule.TemplateScheduleOptions{
1172 // Template level TimeTilDormantAutodelete set to 10 hours
1173 TimeTilDormantAutoDelete: dormantAutoDelete,
1174 },
1175 workspaceUpdate: func(t *testing.T, ctx context.Context, db database.Store, now time.Time,
1176 workspace database.ClaimPrebuiltWorkspaceRow,
1177 ) {
1178 // When: the workspace is marked dormant
1179 dormantWorkspace, err := db.UpdateWorkspaceDormantDeletingAt(ctx, database.UpdateWorkspaceDormantDeletingAtParams{
1180 ID: workspace.ID,
1181 DormantAt: sql.NullTime{
1182 Time: now,
1183 Valid: true,
1184 },
1185 })
1186 require.NoError(t, err)
1187 require.NotNil(t, dormantWorkspace.DormantAt)
1188 },
1189 assertWorkspace: func(t *testing.T, ctx context.Context, db database.Store, now time.Time,
1190 isPrebuild bool, workspace database.Workspace,
1191 ) {
1192 if isPrebuild {
1193 // The unclaimed prebuild should have an empty DormantAt and DeletingAt
1194 require.True(t, workspace.DormantAt.Time.IsZero())
1195 require.True(t, workspace.DeletingAt.Time.IsZero())
1196 } else {
1197 // The claimed workspace should have its DormantAt and DeletingAt updated
1198 require.False(t, workspace.DormantAt.Time.IsZero())
1199 require.False(t, workspace.DeletingAt.Time.IsZero())
1200 require.WithinDuration(t, now.UTC(), workspace.DormantAt.Time.UTC(), time.Second)
1201 require.WithinDuration(t, now.Add(dormantAutoDelete).UTC(), workspace.DeletingAt.Time.UTC(), time.Second)

Callers

nothing calls this directly

Calls 15

SetMethod · 0.95
WeekdaysToBitmapFunction · 0.92
WeeklyFunction · 0.92
NowFunction · 0.92
NewDBFunction · 0.92
WithDumpOnFailureFunction · 0.92
ContextFunction · 0.92
UserFunction · 0.92
NewNoopEnqueuerFunction · 0.92
OrganizationFunction · 0.92

Tested by

no test coverage detected