Blocked by autostart requirements
(t *testing.T)
| 3609 | |
| 3610 | // Blocked by autostart requirements |
| 3611 | func TestExecutorAutostartBlocked(t *testing.T) { |
| 3612 | t.Parallel() |
| 3613 | |
| 3614 | now := time.Now() |
| 3615 | var allowed []string |
| 3616 | for _, day := range agplschedule.DaysOfWeek { |
| 3617 | // Skip the day the workspace was created on and if the next day is within 2 |
| 3618 | // hours, skip that too. The cron scheduler will start the workspace every hour, |
| 3619 | // so it can span into the next day. |
| 3620 | if day != now.UTC().Weekday() && |
| 3621 | day != now.UTC().Add(time.Hour*2).Weekday() { |
| 3622 | allowed = append(allowed, day.String()) |
| 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | var ( |
| 3627 | sched = must(cron.Weekly("CRON_TZ=UTC 0 * * * *")) |
| 3628 | tickCh = make(chan time.Time) |
| 3629 | statsCh = make(chan autobuild.Stats) |
| 3630 | |
| 3631 | logger = slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug) |
| 3632 | client, owner = coderdenttest.New(t, &coderdenttest.Options{ |
| 3633 | Options: &coderdtest.Options{ |
| 3634 | AutobuildTicker: tickCh, |
| 3635 | IncludeProvisionerDaemon: true, |
| 3636 | AutobuildStats: statsCh, |
| 3637 | TemplateScheduleStore: schedule.NewEnterpriseTemplateScheduleStore(agplUserQuietHoursScheduleStore(), notifications.NewNoopEnqueuer(), logger, nil), |
| 3638 | }, |
| 3639 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 3640 | Features: license.Features{codersdk.FeatureAdvancedTemplateScheduling: 1}, |
| 3641 | }, |
| 3642 | }) |
| 3643 | version = coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) |
| 3644 | template = coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID, func(request *codersdk.CreateTemplateRequest) { |
| 3645 | request.AutostartRequirement = &codersdk.TemplateAutostartRequirement{ |
| 3646 | DaysOfWeek: allowed, |
| 3647 | } |
| 3648 | }) |
| 3649 | _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 3650 | workspace = coderdtest.CreateWorkspace(t, client, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) { |
| 3651 | cwr.AutostartSchedule = ptr.Ref(sched.String()) |
| 3652 | }) |
| 3653 | _ = coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) |
| 3654 | ) |
| 3655 | |
| 3656 | // Given: workspace is stopped |
| 3657 | workspace = coderdtest.MustTransitionWorkspace(t, client, workspace.ID, codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop) |
| 3658 | |
| 3659 | // When: the autobuild executor ticks into the future |
| 3660 | go func() { |
| 3661 | tickCh <- workspace.LatestBuild.CreatedAt.Add(2 * time.Hour) |
| 3662 | close(tickCh) |
| 3663 | }() |
| 3664 | |
| 3665 | // Then: the workspace should not be started. |
| 3666 | stats := <-statsCh |
| 3667 | require.Len(t, stats.Errors, 0) |
| 3668 | require.Len(t, stats.Transitions, 0) |
nothing calls this directly
no test coverage detected