Skip to content

fix: set prebuilds lifecycle parameters on creation and claim #19252

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: lifecycle executor prebuilds test
  • Loading branch information
ssncferreira committed Aug 11, 2025
commit b2c130ffcaae3c5e9897a2f4c8d9b45df0905c8f
18 changes: 16 additions & 2 deletions coderd/autobuild/lifecycle_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,14 @@ func TestExecutorPrebuilds(t *testing.T) {
require.Equal(t, codersdk.BuildReasonInitiator, prebuild.LatestBuild.Reason)

// Given: a user claims the prebuilt workspace
dbWorkspace := dbgen.ClaimPrebuild(t, db, user.ID, "claimedWorkspace-autostop", preset.ID)
dbWorkspace := dbgen.ClaimPrebuild(
t, db,
user.ID,
"claimedWorkspace-autostop",
preset.ID,
sql.NullString{},
sql.NullTime{},
sql.NullInt64{})
workspace := coderdtest.MustWorkspace(t, client, dbWorkspace.ID)

// When: the autobuild executor ticks *after* the deadline:
Expand Down Expand Up @@ -1353,7 +1360,14 @@ func TestExecutorPrebuilds(t *testing.T) {
database.WorkspaceTransitionStart)

// Given: a user claims the prebuilt workspace
dbWorkspace := dbgen.ClaimPrebuild(t, db, user.ID, "claimedWorkspace-autostart", preset.ID)
dbWorkspace := dbgen.ClaimPrebuild(
t, db,
user.ID,
"claimedWorkspace-autostart",
preset.ID,
autostartSched,
sql.NullTime{},
sql.NullInt64{})
workspace := coderdtest.MustWorkspace(t, client, dbWorkspace.ID)

// Given: the prebuilt workspace goes to a stop status
Expand Down
17 changes: 13 additions & 4 deletions coderd/database/dbgen/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,14 +1436,23 @@ func UserSecret(t testing.TB, db database.Store, seed database.UserSecret) datab
return userSecret
}

func ClaimPrebuild(t testing.TB, db database.Store, newUserID uuid.UUID, newName string, presetID uuid.UUID) database.ClaimPrebuiltWorkspaceRow {
func ClaimPrebuild(
t testing.TB,
db database.Store,
newUserID uuid.UUID,
newName string,
presetID uuid.UUID,
autostartSchedule sql.NullString,
nextStartAt sql.NullTime,
ttl sql.NullInt64,
) database.ClaimPrebuiltWorkspaceRow {
claimedWorkspace, err := db.ClaimPrebuiltWorkspace(genCtx, database.ClaimPrebuiltWorkspaceParams{
NewUserID: newUserID,
NewName: newName,
PresetID: presetID,
AutostartSchedule: sql.NullString{},
NextStartAt: sql.NullTime{},
WorkspaceTtl: sql.NullInt64{},
AutostartSchedule: autostartSchedule,
NextStartAt: nextStartAt,
WorkspaceTtl: ttl,
})
require.NoError(t, err, "claim prebuilt workspace")

Expand Down
Loading