@@ -563,6 +563,53 @@ func TestExecutorWorkspaceAutostopBeforeDeadline(t *testing.T) {
563
563
assert .Len (t , stats .Transitions , 0 )
564
564
}
565
565
566
+ func TestExecuteAutostopSuspendedUser (t * testing.T ) {
567
+ t .Parallel ()
568
+
569
+ var (
570
+ ctx = testutil .Context (t , testutil .WaitShort )
571
+ sched = mustSchedule (t , "CRON_TZ=UTC 0 * * * *" )
572
+ tickCh = make (chan time.Time )
573
+ statsCh = make (chan autobuild.Stats )
574
+ client = coderdtest .New (t , & coderdtest.Options {
575
+ AutobuildTicker : tickCh ,
576
+ IncludeProvisionerDaemon : true ,
577
+ AutobuildStats : statsCh ,
578
+ })
579
+ )
580
+
581
+ admin := coderdtest .CreateFirstUser (t , client )
582
+ version := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
583
+ coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
584
+ template := coderdtest .CreateTemplate (t , client , admin .OrganizationID , version .ID )
585
+ userClient , user := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID )
586
+ workspace := coderdtest .CreateWorkspace (t , userClient , admin .OrganizationID , template .ID , func (cwr * codersdk.CreateWorkspaceRequest ) {
587
+ cwr .AutostartSchedule = ptr .Ref (sched .String ())
588
+ })
589
+ coderdtest .AwaitWorkspaceBuildJobCompleted (t , userClient , workspace .LatestBuild .ID )
590
+
591
+ // Given: workspace is started, and the user is suspended.
592
+ workspace = coderdtest .MustWorkspace (t , userClient , workspace .ID )
593
+ _ , err := client .UpdateUserStatus (ctx , user .ID .String (), codersdk .UserStatusSuspended )
594
+ require .NoError (t , err , "update user status" )
595
+
596
+ // When: the autobuild executor ticks after the scheduled time
597
+ go func () {
598
+ tickCh <- sched .Next (workspace .LatestBuild .CreatedAt )
599
+ close (tickCh )
600
+ }()
601
+
602
+ // Then: nothing should happen
603
+ stats := <- statsCh
604
+ assert .Len (t , stats .Errors , 0 )
605
+ assert .Len (t , stats .Transitions , 1 )
606
+ assert .Equal (t , stats .Transitions [workspace .ID ], database .WorkspaceTransitionStop )
607
+
608
+ // Wait for stop to complete
609
+ workspace = coderdtest .MustWorkspace (t , client , workspace .ID )
610
+ _ = coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , workspace .LatestBuild .ID )
611
+ }
612
+
566
613
func TestExecutorWorkspaceAutostopNoWaitChangedMyMind (t * testing.T ) {
567
614
t .Parallel ()
568
615
0 commit comments