Skip to content

fix: schedule autobuild directly on TestExecutorAutostopTemplateDisabled #10453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions coderd/autobuild/lifecycle_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ func TestExecutorAutostopTemplateDisabled(t *testing.T) {

// Given: we have a workspace built from a template that disallows user autostop
var (
sched = mustSchedule(t, "CRON_TZ=UTC 0 * * * *")
tickCh = make(chan time.Time)
statsCh = make(chan autobuild.Stats)

Expand All @@ -761,26 +760,38 @@ func TestExecutorAutostopTemplateDisabled(t *testing.T) {
},
},
})
// Given: we have a user with a workspace configured to autostart some time in the future
// Given: we have a user with a workspace configured to autostop 30 minutes in the future
workspace = mustProvisionWorkspace(t, client, func(cwr *codersdk.CreateWorkspaceRequest) {
cwr.TTLMillis = ptr.Ref(8 * time.Hour.Milliseconds())
cwr.TTLMillis = ptr.Ref(30 * time.Minute.Milliseconds())
})
)

// When: we create the workspace
// Then: the deadline should be set to the template default TTL
assert.WithinDuration(t, workspace.LatestBuild.CreatedAt.Add(time.Hour), workspace.LatestBuild.Deadline.Time, time.Minute)

// When: the autobuild executor ticks before the next scheduled time
// When: the autobuild executor ticks after the workspace setting, but before the template setting:
go func() {
tickCh <- sched.Next(workspace.LatestBuild.CreatedAt).Add(time.Minute)
close(tickCh)
tickCh <- workspace.LatestBuild.CreatedAt.Add(45 * time.Minute)
}()

// Then: nothing should happen
stats := <-statsCh
assert.NoError(t, stats.Error)
assert.Len(t, stats.Transitions, 0)

// When: the autobuild executor ticks after the template setting:
go func() {
tickCh <- workspace.LatestBuild.CreatedAt.Add(61 * time.Minute)
close(tickCh)
}()

// Then: the workspace should be stopped
stats = <-statsCh
assert.NoError(t, stats.Error)
assert.Len(t, stats.Transitions, 1)
assert.Contains(t, stats.Transitions, workspace.ID)
assert.Equal(t, database.WorkspaceTransitionStop, stats.Transitions[workspace.ID])
}

// Test that an AGPL AccessControlStore properly disables
Expand Down