@@ -2,6 +2,7 @@ package executor_test
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"testing"
6
7
"time"
7
8
@@ -274,6 +275,45 @@ func Test_Executor_Workspace_Deleted(t *testing.T) {
274
275
}, 5 * time .Second , 250 * time .Millisecond )
275
276
}
276
277
278
+ func Test_Executor_Workspace_TooEarly (t * testing.T ) {
279
+ t .Parallel ()
280
+
281
+ var (
282
+ ctx = context .Background ()
283
+ err error
284
+ tickCh = make (chan time.Time )
285
+ client = coderdtest .New (t , & coderdtest.Options {
286
+ LifecycleTicker : tickCh ,
287
+ })
288
+ // Given: we have a user with a workspace
289
+ workspace = mustProvisionWorkspace (t , client )
290
+ )
291
+
292
+ // Given: the workspace initially has autostart disabled
293
+ require .Empty (t , workspace .AutostopSchedule )
294
+
295
+ // When: we enable workspace autostart with some time in the future
296
+ futureTime := time .Now ().Add (time .Hour )
297
+ futureTimeCron := fmt .Sprintf ("%d %d * * *" , futureTime .Minute (), futureTime .Hour ())
298
+ sched , err := schedule .Weekly (futureTimeCron )
299
+ require .NoError (t , err )
300
+ require .NoError (t , client .UpdateWorkspaceAutostop (ctx , workspace .ID , codersdk.UpdateWorkspaceAutostopRequest {
301
+ Schedule : sched .String (),
302
+ }))
303
+
304
+ // When: the lifecycle executor ticks
305
+ go func () {
306
+ tickCh <- time .Now ().UTC ()
307
+ close (tickCh )
308
+ }()
309
+
310
+ // Then: nothing should happen
311
+ require .Never (t , func () bool {
312
+ ws := mustWorkspace (t , client , workspace .ID )
313
+ return ws .LatestBuild .Transition != database .WorkspaceTransitionStart
314
+ }, 5 * time .Second , 250 * time .Millisecond )
315
+ }
316
+
277
317
func mustProvisionWorkspace (t * testing.T , client * codersdk.Client ) codersdk.Workspace {
278
318
t .Helper ()
279
319
coderdtest .NewProvisionerDaemon (t , client )
0 commit comments