Skip to content

Commit d787abb

Browse files
chore: re-add old test but refactored
1 parent 1698b13 commit d787abb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

coderd/autobuild/lifecycle_executor_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,41 @@ func TestExecuteAutostopSuspendedUser(t *testing.T) {
702702
assert.Equal(t, codersdk.WorkspaceStatusStopped, workspaceBuild.Status)
703703
}
704704

705+
func TestExecutorWorkspaceAutostopNoWaitChangedMyMind(t *testing.T) {
706+
t.Parallel()
707+
708+
var (
709+
ctx = context.Background()
710+
tickCh = make(chan time.Time)
711+
statsCh = make(chan autobuild.Stats)
712+
client = coderdtest.New(t, &coderdtest.Options{
713+
AutobuildTicker: tickCh,
714+
IncludeProvisionerDaemon: true,
715+
AutobuildStats: statsCh,
716+
})
717+
// Given: we have a user with a workspace
718+
workspace = mustProvisionWorkspace(t, client)
719+
)
720+
721+
// Given: the user changes their mind and decides their workspace should not autostop
722+
err := client.UpdateWorkspaceTTL(ctx, workspace.ID, codersdk.UpdateWorkspaceTTLRequest{TTLMillis: nil})
723+
require.NoError(t, err)
724+
725+
// Then: the deadline should be set to zero
726+
updated := coderdtest.MustWorkspace(t, client, workspace.ID)
727+
assert.True(t, !updated.LatestBuild.Deadline.Valid)
728+
729+
// When: the autobuild executor ticks after the original deadline
730+
go func() {
731+
tickCh <- workspace.LatestBuild.Deadline.Time.Add(time.Minute)
732+
}()
733+
734+
// Then: the workspace should not stop
735+
stats := <-statsCh
736+
assert.Len(t, stats.Errors, 0)
737+
assert.Len(t, stats.Transitions, 0)
738+
}
739+
705740
func TestExecutorAutostartMultipleOK(t *testing.T) {
706741
if os.Getenv("DB") == "" {
707742
t.Skip(`This test only really works when using a "real" database, similar to a HA setup`)

0 commit comments

Comments
 (0)