@@ -15,6 +15,7 @@ import (
15
15
"github.com/coder/coder/v2/coderd/util/ptr"
16
16
"github.com/coder/coder/v2/testutil"
17
17
18
+ "github.com/stretchr/testify/assert"
18
19
"github.com/stretchr/testify/require"
19
20
)
20
21
@@ -32,13 +33,15 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
32
33
}
33
34
34
35
for _ , tt := range []struct {
35
- name string
36
- transition database.WorkspaceTransition
37
- jobCompletedAt sql.NullTime
38
- buildDeadlineOffset * time.Duration
39
- maxDeadlineOffset * time.Duration
40
- workspaceTTL time.Duration
41
- expectedBump time.Duration
36
+ name string
37
+ transition database.WorkspaceTransition
38
+ jobCompletedAt sql.NullTime
39
+ buildDeadlineOffset * time.Duration
40
+ maxDeadlineOffset * time.Duration
41
+ workspaceTTL time.Duration
42
+ templateTTL time.Duration
43
+ templateDisallowsUserAutostop bool
44
+ expectedBump time.Duration
42
45
}{
43
46
{
44
47
name : "NotFinishedYet" ,
@@ -97,7 +100,18 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
97
100
jobCompletedAt : sql.NullTime {Valid : true , Time : dbtime .Now ().Add (- time .Minute )},
98
101
buildDeadlineOffset : ptr .Ref (- time .Minute ),
99
102
workspaceTTL : 8 * time .Hour ,
100
- expectedBump : 0 ,
103
+ },
104
+ {
105
+ // A workspace built from a template that disallows user autostop should bump
106
+ // by the template TTL instead.
107
+ name : "TemplateDisallowsUserAutostop" ,
108
+ transition : database .WorkspaceTransitionStart ,
109
+ jobCompletedAt : sql.NullTime {Valid : true , Time : dbtime .Now ().Add (- 24 * time .Minute )},
110
+ buildDeadlineOffset : ptr .Ref (8 * time .Hour - 24 * time .Minute ),
111
+ workspaceTTL : 6 * time .Hour ,
112
+ templateTTL : 8 * time .Hour ,
113
+ templateDisallowsUserAutostop : true ,
114
+ expectedBump : 8 * time .Hour ,
101
115
},
102
116
} {
103
117
tt := tt
@@ -144,6 +158,13 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
144
158
buildID = uuid .New ()
145
159
)
146
160
161
+ require .NoError (t , db .UpdateTemplateScheduleByID (ctx , database.UpdateTemplateScheduleByIDParams {
162
+ ID : template .ID ,
163
+ UpdatedAt : dbtime .Now (),
164
+ AllowUserAutostop : ! tt .templateDisallowsUserAutostop ,
165
+ DefaultTTL : int64 (tt .templateTTL ),
166
+ }), "unexpected error updating template schedule" )
167
+
147
168
var buildNumber int32 = 1
148
169
// Insert a number of previous workspace builds.
149
170
for i := 0 ; i < 5 ; i ++ {
@@ -202,13 +223,13 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
202
223
require .NoError (t , err , "unexpected error getting latest workspace build" )
203
224
require .Equal (t , bld .MaxDeadline .UTC (), updatedBuild .MaxDeadline .UTC (), "max_deadline should not have changed" )
204
225
if tt .expectedBump == 0 {
205
- require .Equal (t , bld .UpdatedAt .UTC (), updatedBuild .UpdatedAt .UTC (), "should not have bumped updated_at" )
206
- require .Equal (t , bld .Deadline .UTC (), updatedBuild .Deadline .UTC (), "should not have bumped deadline" )
226
+ assert .Equal (t , bld .UpdatedAt .UTC (), updatedBuild .UpdatedAt .UTC (), "should not have bumped updated_at" )
227
+ assert .Equal (t , bld .Deadline .UTC (), updatedBuild .Deadline .UTC (), "should not have bumped deadline" )
207
228
return
208
229
}
209
- require .NotEqual (t , bld .UpdatedAt .UTC (), updatedBuild .UpdatedAt .UTC (), "should have bumped updated_at" )
230
+ assert .NotEqual (t , bld .UpdatedAt .UTC (), updatedBuild .UpdatedAt .UTC (), "should have bumped updated_at" )
210
231
if tt .maxDeadlineOffset != nil {
211
- require .Equal (t , bld .MaxDeadline .UTC (), updatedBuild .MaxDeadline .UTC (), "new deadline must equal original max deadline" )
232
+ assert .Equal (t , bld .MaxDeadline .UTC (), updatedBuild .MaxDeadline .UTC (), "new deadline must equal original max deadline" )
212
233
return
213
234
}
214
235
0 commit comments