@@ -43,7 +43,9 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
43
43
templateTTL time.Duration
44
44
templateDisallowsUserAutostop bool
45
45
expectedBump time.Duration
46
- nextAutostart time.Time
46
+ // If the tests get queued, we need to be able to set the next autostart
47
+ // based on the actual time the unit test is running.
48
+ nextAutostart func (now time.Time ) time.Time
47
49
}{
48
50
{
49
51
name : "NotFinishedYet" ,
@@ -93,7 +95,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
93
95
buildDeadlineOffset : ptr .Ref (- 30 * time .Minute ),
94
96
workspaceTTL : 8 * time .Hour ,
95
97
expectedBump : 8 * time .Hour + 30 * time .Minute ,
96
- nextAutostart : time .Now (). Add (time .Minute * 30 ),
98
+ nextAutostart : func ( now time.Time ) time. Time { return now . Add (time .Minute * 30 ) } ,
97
99
},
98
100
{
99
101
name : "MaxDeadline" ,
@@ -127,20 +129,24 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
127
129
// by the template TTL instead.
128
130
name : "TemplateDisallowsUserAutostop" ,
129
131
transition : database .WorkspaceTransitionStart ,
130
- jobCompletedAt : sql.NullTime {Valid : true , Time : dbtime .Now ().Add (- 7 * time .Hour )},
132
+ jobCompletedAt : sql.NullTime {Valid : true , Time : dbtime .Now ().Add (- 3 * time .Hour )},
131
133
buildDeadlineOffset : ptr .Ref (- 30 * time .Minute ),
132
134
workspaceTTL : 2 * time .Hour ,
133
135
templateTTL : 10 * time .Hour ,
134
136
templateDisallowsUserAutostop : true ,
135
137
expectedBump : 10 * time .Hour + (time .Minute * 30 ),
136
- nextAutostart : time .Now (). Add (time .Minute * 30 ),
138
+ nextAutostart : func ( now time.Time ) time. Time { return now . Add (time .Minute * 30 ) } ,
137
139
},
138
140
} {
139
141
tt := tt
140
142
for _ , tz := range timezones {
141
143
tz := tz
142
144
t .Run (tt .name + "/" + tz , func (t * testing.T ) {
143
145
t .Parallel ()
146
+ nextAutostart := tt .nextAutostart
147
+ if tt .nextAutostart == nil {
148
+ nextAutostart = func (now time.Time ) time.Time { return time.Time {} }
149
+ }
144
150
145
151
var (
146
152
now = dbtime .Now ()
@@ -237,7 +243,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
237
243
238
244
// Bump duration is measured from the time of the bump, so we measure from here.
239
245
start := dbtime .Now ()
240
- agentapi .ActivityBumpWorkspace (ctx , log , db , bld .WorkspaceID , tt . nextAutostart )
246
+ agentapi .ActivityBumpWorkspace (ctx , log , db , bld .WorkspaceID , nextAutostart ( start ) )
241
247
end := dbtime .Now ()
242
248
243
249
// Validate our state after bump
0 commit comments