(t *testing.T)
| 781 | } |
| 782 | |
| 783 | func TestExecuteAutostopSuspendedUser(t *testing.T) { |
| 784 | t.Parallel() |
| 785 | |
| 786 | var ( |
| 787 | tickCh = make(chan time.Time) |
| 788 | statsCh = make(chan autobuild.Stats) |
| 789 | client, db = coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 790 | AutobuildTicker: tickCh, |
| 791 | IncludeProvisionerDaemon: true, |
| 792 | AutobuildStats: statsCh, |
| 793 | }) |
| 794 | ) |
| 795 | |
| 796 | admin := coderdtest.CreateFirstUser(t, client) |
| 797 | // Wait for provisioner to be available |
| 798 | coderdtest.MustWaitForAnyProvisioner(t, db) |
| 799 | version := coderdtest.CreateTemplateVersion(t, client, admin.OrganizationID, nil) |
| 800 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 801 | template := coderdtest.CreateTemplate(t, client, admin.OrganizationID, version.ID) |
| 802 | userClient, user := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID) |
| 803 | workspace := coderdtest.CreateWorkspace(t, userClient, template.ID) |
| 804 | coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, workspace.LatestBuild.ID) |
| 805 | |
| 806 | // Given: workspace is running, and the user is suspended. |
| 807 | workspace = coderdtest.MustWorkspace(t, userClient, workspace.ID) |
| 808 | require.Equal(t, codersdk.WorkspaceStatusRunning, workspace.LatestBuild.Status) |
| 809 | |
| 810 | ctx := testutil.Context(t, testutil.WaitShort) |
| 811 | |
| 812 | _, err := client.UpdateUserStatus(ctx, user.ID.String(), codersdk.UserStatusSuspended) |
| 813 | require.NoError(t, err, "update user status") |
| 814 | |
| 815 | // When: the autobuild executor ticks after the scheduled time |
| 816 | go func() { |
| 817 | tickCh <- time.Unix(0, 0) // the exact time is not important |
| 818 | close(tickCh) |
| 819 | }() |
| 820 | |
| 821 | // Then: the workspace should be stopped |
| 822 | stats := <-statsCh |
| 823 | assert.Len(t, stats.Errors, 0) |
| 824 | assert.Len(t, stats.Transitions, 1) |
| 825 | assert.Equal(t, stats.Transitions[workspace.ID], database.WorkspaceTransitionStop) |
| 826 | |
| 827 | // Wait for stop to complete |
| 828 | workspace = coderdtest.MustWorkspace(t, client, workspace.ID) |
| 829 | workspaceBuild := coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) |
| 830 | assert.Equal(t, codersdk.WorkspaceStatusStopped, workspaceBuild.Status) |
| 831 | } |
| 832 | |
| 833 | func TestExecutorWorkspaceAutostopNoWaitChangedMyMind(t *testing.T) { |
| 834 | t.Parallel() |
nothing calls this directly
no test coverage detected