Skip to content

Commit 4b29a80

Browse files
committed
fix some grammar
1 parent 416d39e commit 4b29a80

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-34
lines changed

coderd/database/queries/workspaces.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ LEFT JOIN
415415
INNER JOIN
416416
provisioner_jobs ON workspace_builds.job_id = provisioner_jobs.id
417417
INNER JOIN
418-
templates ON workspaces.template_id = templates.id
418+
templates ON workspaces.template_id = templates.id
419419
WHERE
420420
workspace_builds.build_number = (
421421
SELECT
@@ -458,15 +458,15 @@ WHERE
458458
-- If the workspace's template has an inactivity_ttl set
459459
-- it may be eligible for locking.
460460
(
461-
templates.inactivity_ttl > 0 AND
462-
workspaces.locked_at IS NULL
461+
templates.inactivity_ttl > 0 AND
462+
workspaces.locked_at IS NULL
463463
) OR
464464

465465
-- If the workspace's template has a locked_ttl set
466466
-- and the workspace is already locked
467467
(
468-
templates.locked_ttl > 0 AND
469-
workspaces.locked_at IS NOT NULL
468+
templates.locked_ttl > 0 AND
469+
workspaces.locked_at IS NOT NULL
470470
)
471471
) AND workspaces.deleted = 'false';
472472

enterprise/coderd/workspaces_test.go

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -210,25 +210,25 @@ func TestWorkspaceAutobuild(t *testing.T) {
210210
})
211211
)
212212
user := coderdtest.CreateFirstUser(t, client)
213-
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
214-
Features: license.Features{
215-
codersdk.FeatureAdvancedTemplateScheduling: 1,
216-
},
217-
})
213+
_ = coderdenttest.AddFullLicense(t, client)
218214
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
219215
Parse: echo.ParseComplete,
220216
ProvisionPlan: echo.ProvisionComplete,
221217
ProvisionApply: echo.ProvisionComplete,
222218
})
223219
// Create a template without setting a failure_ttl.
224220
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
221+
require.Zero(t, template.InactivityTTLMillis)
222+
require.Zero(t, template.FailureTTLMillis)
223+
require.Zero(t, template.LockedTTLMillis)
224+
225225
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
226226
ws := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
227227
build := coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
228228
require.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
229229
ticker <- time.Now()
230230
stats := <-statCh
231-
// Expect no transitions since the field is unset on the template.
231+
// Expect no transitions since the fields are unset on the template.
232232
require.Len(t, stats.Transitions, 0)
233233
})
234234

@@ -258,26 +258,33 @@ func TestWorkspaceAutobuild(t *testing.T) {
258258
ProvisionPlan: echo.ProvisionComplete,
259259
ProvisionApply: echo.ProvisionComplete,
260260
})
261+
// Create a template with a short inactivity ttl so we don't have to wait
262+
// too long.
261263
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
262264
ctr.InactivityTTLMillis = ptr.Ref[int64](inactiveTTL.Milliseconds())
263265
})
264266
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
267+
265268
ws := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
266269
build := coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
267270
require.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
271+
272+
// Wait to trigger the inactivity threshold.
268273
require.Eventually(t,
269274
func() bool {
270275
return database.Now().Sub(ws.LastUsedAt) > inactiveTTL
271276
},
272277
testutil.IntervalMedium, testutil.IntervalFast)
273278
ticker <- time.Now()
274279
stats := <-statCh
280+
275281
// Expect workspace to transition to stopped state for breaching
276282
// failure TTL.
277283
require.Len(t, stats.Transitions, 1)
278284
require.Equal(t, stats.Transitions[ws.ID], database.WorkspaceTransitionStop)
279-
ws = coderdtest.MustWorkspace(t, client, ws.ID)
285+
280286
// The workspace should be locked.
287+
ws = coderdtest.MustWorkspace(t, client, ws.ID)
281288
require.NotNil(t, ws.LockedAt)
282289
lastUsedAt := ws.LastUsedAt
283290

@@ -308,11 +315,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
308315
})
309316
)
310317
user := coderdtest.CreateFirstUser(t, client)
311-
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
312-
Features: license.Features{
313-
codersdk.FeatureAdvancedTemplateScheduling: 1,
314-
},
315-
})
318+
_ = coderdenttest.AddFullLicense(t, client)
316319
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
317320
Parse: echo.ParseComplete,
318321
ProvisionPlan: echo.ProvisionComplete,
@@ -331,6 +334,9 @@ func TestWorkspaceAutobuild(t *testing.T) {
331334
require.Len(t, stats.Transitions, 0)
332335
})
333336

337+
// This is kind of a dumb test but it exists to offer some marginal
338+
// confidence that bug in the auto-deletion logic doesn't delete running
339+
// workspaces.
334340
t.Run("UnlockedWorkspacesNotDeleted", func(t *testing.T) {
335341
t.Parallel()
336342

@@ -349,11 +355,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
349355
})
350356
)
351357
user := coderdtest.CreateFirstUser(t, client)
352-
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
353-
Features: license.Features{
354-
codersdk.FeatureAdvancedTemplateScheduling: 1,
355-
},
356-
})
358+
_ = coderdenttest.AddFullLicense(t, client)
357359
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
358360
Parse: echo.ParseComplete,
359361
ProvisionPlan: echo.ProvisionComplete,
@@ -365,6 +367,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
365367
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
366368
ws := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
367369
build := coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
370+
require.Nil(t, ws.LockedAt)
368371
require.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
369372
require.Eventually(t,
370373
func() bool {
@@ -378,6 +381,9 @@ func TestWorkspaceAutobuild(t *testing.T) {
378381
require.Len(t, stats.Transitions, 0)
379382
})
380383

384+
// Assert that a stopped workspace that breaches the inactivity threshold
385+
// does not trigger a build transition but is still placed in the
386+
// lock state.
381387
t.Run("InactiveStoppedWorkspaceNoTransition", func(t *testing.T) {
382388
t.Parallel()
383389

@@ -396,11 +402,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
396402
})
397403
)
398404
user := coderdtest.CreateFirstUser(t, client)
399-
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
400-
Features: license.Features{
401-
codersdk.FeatureAdvancedTemplateScheduling: 1,
402-
},
403-
})
405+
_ = coderdenttest.AddFullLicense(t, client)
404406
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
405407
Parse: echo.ParseComplete,
406408
ProvisionPlan: echo.ProvisionComplete,
@@ -410,6 +412,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
410412
ctr.InactivityTTLMillis = ptr.Ref[int64](inactiveTTL.Milliseconds())
411413
})
412414
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
415+
413416
ws := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
414417
build := coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
415418
require.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
@@ -466,41 +469,50 @@ func TestWorkspaceAutobuild(t *testing.T) {
466469
ctr.InactivityTTLMillis = ptr.Ref[int64](transitionTTL.Milliseconds())
467470
ctr.LockedTTLMillis = ptr.Ref[int64](transitionTTL.Milliseconds())
468471
})
469-
470472
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
473+
471474
ws := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
472475
build := coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
473476
require.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
477+
474478
require.Eventually(t,
475479
func() bool {
476480
return database.Now().Sub(ws.LastUsedAt) > transitionTTL
477481
},
478482
testutil.IntervalMedium, testutil.IntervalFast)
483+
479484
ticker <- time.Now()
480485
stats := <-statCh
481486
// Expect workspace to transition to stopped state for breaching
482487
// inactive TTL.
483488
require.Len(t, stats.Transitions, 1)
484489
require.Equal(t, stats.Transitions[ws.ID], database.WorkspaceTransitionStop)
490+
485491
ws = coderdtest.MustWorkspace(t, client, ws.ID)
486492
// The workspace should be locked.
487493
require.NotNil(t, ws.LockedAt)
494+
495+
// Wait for the autobuilder to stop the workspace.
488496
_ = coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
489-
// Wait for the workspace to breach the locked threshold.
497+
498+
// Wait to trigger our locked threshold.
490499
require.Eventually(t,
491500
func() bool {
492501
return database.Now().Sub(*ws.LockedAt) > transitionTTL
493502
},
494503
testutil.IntervalMedium, testutil.IntervalFast)
504+
495505
ticker <- time.Now()
496506
stats = <-statCh
497507
require.Len(t, stats.Transitions, 1)
498508
// The workspace should be scheduled for deletion.
499509
require.Equal(t, stats.Transitions[ws.ID], database.WorkspaceTransitionDelete)
500510

511+
// Wait for the workspace to be deleted.
501512
ws = coderdtest.MustWorkspace(t, client, ws.ID)
502513
_ = coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
503514

515+
// Assert that the workspace is actually deleted.
504516
_, err := client.Workspace(testutil.Context(t, testutil.WaitShort), ws.ID)
505517
require.Error(t, err)
506518
cerr, ok := codersdk.AsError(err)
@@ -575,11 +587,11 @@ func TestWorkspaceAutobuild(t *testing.T) {
575587

576588
ticker <- time.Now()
577589
stats = <-statCh
578-
// Expect no transitions since not enough time has elapsed.
579590
require.Len(t, stats.Transitions, 1)
580591
require.Equal(t, database.WorkspaceTransitionDelete, stats.Transitions[ws.ID])
581592
})
582593

594+
// Assert that a locked workspace does not autostart.
583595
t.Run("LockedNoAutostart", func(t *testing.T) {
584596
t.Parallel()
585597

@@ -621,12 +633,12 @@ func TestWorkspaceAutobuild(t *testing.T) {
621633

622634
// Assert that autostart works when the workspace isn't locked..
623635
tickCh <- sched.Next(ws.LatestBuild.CreatedAt)
624-
// Then: the workspace should eventually be started
625636
stats := <-statsCh
626637
require.NoError(t, stats.Error)
627638
require.Len(t, stats.Transitions, 1)
628639
require.Contains(t, stats.Transitions, ws.ID)
629640
require.Equal(t, database.WorkspaceTransitionStart, stats.Transitions[ws.ID])
641+
630642
ws = coderdtest.MustWorkspace(t, client, ws.ID)
631643
coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
632644

@@ -643,21 +655,21 @@ func TestWorkspaceAutobuild(t *testing.T) {
643655
},
644656
testutil.IntervalMedium, testutil.IntervalFast)
645657

658+
// We should see the workspace get stopped now.
646659
tickCh <- time.Now()
647-
// Then: the workspace should eventually be started
648660
stats = <-statsCh
649661
require.NoError(t, stats.Error)
650662
require.Len(t, stats.Transitions, 1)
651663
require.Contains(t, stats.Transitions, ws.ID)
652664
require.Equal(t, database.WorkspaceTransitionStop, stats.Transitions[ws.ID])
665+
666+
// The workspace should be locked now.
653667
ws = coderdtest.MustWorkspace(t, client, ws.ID)
654668
coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
655-
// The workspace should be locked now.
656669
require.NotNil(t, ws.LockedAt)
657670

658671
// Assert that autostart is no longer triggered since workspace is locked.
659672
tickCh <- sched.Next(ws.LatestBuild.CreatedAt)
660-
// Then: the workspace should eventually be started
661673
stats = <-statsCh
662674
require.Len(t, stats.Transitions, 0)
663675
})

0 commit comments

Comments
 (0)