Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit077439c

Browse files
test: refactor test slightly
1 parentd0f1851 commit077439c

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

‎coderd/autobuild/lifecycle_executor_test.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,10 @@ func TestNotifications(t *testing.T) {
10841084
IncludeProvisionerDaemon:true,
10851085
NotificationsEnqueuer:&notifyEnq,
10861086
TemplateScheduleStore: schedule.MockTemplateScheduleStore{
1087+
SetFn:func(ctx context.Context,db database.Store,template database.Template,options schedule.TemplateScheduleOptions) (database.Template,error) {
1088+
template.TimeTilDormant=int64(options.TimeTilDormant)
1089+
returnschedule.NewAGPLTemplateScheduleStore().Set(ctx,db,template,options)
1090+
},
10871091
GetFn:func(_ context.Context,_ database.Store,_ uuid.UUID) (schedule.TemplateScheduleOptions,error) {
10881092
return schedule.TemplateScheduleOptions{
10891093
UserAutostartEnabled:false,
@@ -1100,7 +1104,10 @@ func TestNotifications(t *testing.T) {
11001104
)
11011105

11021106
coderdtest.AwaitTemplateVersionJobCompleted(t,client,version.ID)
1103-
template:=coderdtest.CreateTemplate(t,client,admin.OrganizationID,version.ID)
1107+
template:=coderdtest.CreateTemplate(t,client,admin.OrganizationID,version.ID,func(ctr*codersdk.CreateTemplateRequest) {
1108+
timeTilDormantMillis:=timeTilDormant.Milliseconds()
1109+
ctr.TimeTilDormantMillis=&timeTilDormantMillis
1110+
})
11041111
userClient,_:=coderdtest.CreateAnotherUser(t,client,admin.OrganizationID)
11051112
workspace:=coderdtest.CreateWorkspace(t,userClient,template.ID)
11061113
coderdtest.AwaitWorkspaceBuildJobCompleted(t,userClient,workspace.LatestBuild.ID)

‎coderd/database/dbgen/dbgen.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ func Workspace(t testing.TB, db database.Store, orig database.WorkspaceTable) da
247247
AutostartSchedule:orig.AutostartSchedule,
248248
Ttl:orig.Ttl,
249249
AutomaticUpdates:takeFirst(orig.AutomaticUpdates,database.AutomaticUpdatesNever),
250+
NextStartAt:orig.NextStartAt,
250251
})
251252
require.NoError(t,err,"insert workspace")
252253
returnworkspace

‎coderd/database/dbmem/dbmem.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6965,7 +6965,7 @@ func (q *FakeQuerier) GetWorkspacesEligibleForTransition(ctx context.Context, no
69656965

69666966
if!workspace.DormantAt.Valid&&
69676967
template.TimeTilDormant>0&&
6968-
now.Sub(workspace.LastUsedAt)>time.Duration(template.TimeTilDormant) {
6968+
now.Sub(workspace.LastUsedAt)>=time.Duration(template.TimeTilDormant) {
69696969
workspaces=append(workspaces, database.GetWorkspacesEligibleForTransitionRow{
69706970
ID:workspace.ID,
69716971
Name:workspace.Name,
@@ -9955,7 +9955,7 @@ func (q *FakeQuerier) UpdateWorkspaceLastUsedAt(_ context.Context, arg database.
99559955
returnsql.ErrNoRows
99569956
}
99579957

9958-
func (q*FakeQuerier)UpdateWorkspaceNextStartAt(ctx context.Context,arg database.UpdateWorkspaceNextStartAtParams)error {
9958+
func (q*FakeQuerier)UpdateWorkspaceNextStartAt(_ context.Context,arg database.UpdateWorkspaceNextStartAtParams)error {
99599959
err:=validateDatabaseType(arg)
99609960
iferr!=nil {
99619961
returnerr

‎coderd/database/queries.sql.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaces.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ WHERE
635635
(
636636
workspaces.dormant_at ISNULLAND
637637
templates.time_til_dormant>0AND
638-
(@now ::timestamptz)-workspaces.last_used_at> (INTERVAL'1 millisecond'* (templates.time_til_dormant/1000000))
638+
(@now ::timestamptz)-workspaces.last_used_at>= (INTERVAL'1 millisecond'* (templates.time_til_dormant/1000000))
639639
)OR
640640

641641
-- A workspace may be eligible for deletion if the following are true:

‎coderd/workspaces.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ func createWorkspace(
557557

558558
nextStartAt:= sql.NullTime{}
559559
ifdbAutostartSchedule.Valid {
560-
time,_:=schedule.NextAutostart(dbtime.Now(),dbAutostartSchedule.String,templateSchedule)
561-
nextStartAt= sql.NullTime{Valid:true,Time:time}
560+
next,_:=schedule.NextAutostart(dbtime.Now(),dbAutostartSchedule.String,templateSchedule)
561+
nextStartAt= sql.NullTime{Valid:true,Time:next}
562562
}
563563

564564
dbTTL,err:=validWorkspaceTTLMillis(req.TTLMillis,templateSchedule.DefaultTTL)
@@ -883,8 +883,8 @@ func (api *API) putWorkspaceAutostart(rw http.ResponseWriter, r *http.Request) {
883883

884884
nextStartAt:= sql.NullTime{}
885885
ifdbSched.Valid {
886-
time,_:=schedule.NextAutostart(dbtime.Now(),dbSched.String,templateSchedule)
887-
nextStartAt= sql.NullTime{Valid:true,Time:time}
886+
next,_:=schedule.NextAutostart(dbtime.Now(),dbSched.String,templateSchedule)
887+
nextStartAt= sql.NullTime{Valid:true,Time:next}
888888
}
889889

890890
err=api.Database.UpdateWorkspaceAutostart(ctx, database.UpdateWorkspaceAutostartParams{

‎enterprise/coderd/schedule/template.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/coder/coder/v2/coderd/database/dbauthz"
1919
"github.com/coder/coder/v2/coderd/database/dbtime"
2020
"github.com/coder/coder/v2/coderd/notifications"
21-
"github.com/coder/coder/v2/coderd/schedule"
2221
agpl"github.com/coder/coder/v2/coderd/schedule"
2322
"github.com/coder/coder/v2/coderd/tracing"
2423
"github.com/coder/coder/v2/codersdk"
@@ -311,7 +310,7 @@ func (s *EnterpriseTemplateScheduleStore) updateWorkspaceBuild(ctx context.Conte
311310
returnxerrors.Errorf("get template schedule options: %w",err)
312311
}
313312

314-
nextStartAt,_:=schedule.NextAutostart(dbtime.Now(),workspace.AutostartSchedule.String,templateScheduleOptions)
313+
nextStartAt,_:=agpl.NextAutostart(dbtime.Now(),workspace.AutostartSchedule.String,templateScheduleOptions)
315314

316315
err=db.UpdateWorkspaceNextStartAt(ctx, database.UpdateWorkspaceNextStartAtParams{
317316
ID:workspace.ID,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp