Skip to content

Commit ae39e40

Browse files
committed
Tests for zero bump
1 parent 359d188 commit ae39e40

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

coderd/agentapi/activitybump_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
148148
templateActivityBump: 5 * time.Hour, // instead of default 1h
149149
expectedBump: 5 * time.Hour,
150150
},
151+
{
152+
// Activity bump duration is 0.
153+
name: "TemplateCustomActivityBumpZero",
154+
transition: database.WorkspaceTransitionStart,
155+
jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-30 * time.Minute)},
156+
buildDeadlineOffset: ptr.Ref(-30 * time.Minute),
157+
workspaceTTL: 8 * time.Hour,
158+
templateActivityBump: -1, // negative values get changed to 0 in the test
159+
expectedBump: 0,
160+
},
151161
} {
152162
tt := tt
153163
for _, tz := range timezones {
@@ -198,7 +208,10 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
198208
)
199209

200210
activityBump := 1 * time.Hour
201-
if tt.templateActivityBump != 0 {
211+
if tt.templateActivityBump < 0 {
212+
// less than 0 => 0
213+
activityBump = 0
214+
} else if tt.templateActivityBump != 0 {
202215
activityBump = tt.templateActivityBump
203216
}
204217
require.NoError(t, db.UpdateTemplateScheduleByID(ctx, database.UpdateTemplateScheduleByIDParams{

coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ func (q *FakeQuerier) ActivityBumpWorkspace(ctx context.Context, arg database.Ac
839839
if err != nil {
840840
return err
841841
}
842+
if template.ActivityBump == 0 {
843+
return nil
844+
}
842845
activityBump := time.Duration(template.ActivityBump)
843846

844847
var ttlDur time.Duration

coderd/database/queries/activitybump.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ WITH latest AS (
1212
workspace_builds.max_deadline::timestamp with time zone AS build_max_deadline,
1313
workspace_builds.transition AS build_transition,
1414
provisioner_jobs.completed_at::timestamp with time zone AS job_completed_at,
15+
templates.activity_bump AS activity_bump,
1516
(
1617
CASE
1718
-- If the extension would push us over the next_autostart
@@ -67,6 +68,8 @@ SET
6768
FROM latest l
6869
WHERE wb.id = l.build_id
6970
AND l.job_completed_at IS NOT NULL
71+
-- We only bump if the template has an activity bump duration set.
72+
AND l.activity_bump IS NOT NULL
7073
AND l.build_transition = 'start'
7174
-- We only bump if the raw interval is positive and non-zero.
7275
AND l.ttl_interval > '0 seconds'::interval

0 commit comments

Comments
 (0)