mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
feat: allow removing deadline for running workspace (#16085)
Fixes https://github.com/coder/coder/issues/9775 When a workspace's TTL is removed, and the workspace is running, the deadline is removed from the workspace. This also modifies the frontend to not show a confirmation dialog when the change is to remove autostop.
This commit is contained in:
@@ -722,45 +722,17 @@ func TestExecutorWorkspaceAutostopNoWaitChangedMyMind(t *testing.T) {
|
||||
err := client.UpdateWorkspaceTTL(ctx, workspace.ID, codersdk.UpdateWorkspaceTTLRequest{TTLMillis: nil})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Then: the deadline should still be the original value
|
||||
// Then: the deadline should be set to zero
|
||||
updated := coderdtest.MustWorkspace(t, client, workspace.ID)
|
||||
assert.WithinDuration(t, workspace.LatestBuild.Deadline.Time, updated.LatestBuild.Deadline.Time, time.Minute)
|
||||
assert.True(t, !updated.LatestBuild.Deadline.Valid)
|
||||
|
||||
// When: the autobuild executor ticks after the original deadline
|
||||
go func() {
|
||||
tickCh <- workspace.LatestBuild.Deadline.Time.Add(time.Minute)
|
||||
}()
|
||||
|
||||
// Then: the workspace should stop
|
||||
stats := <-statsCh
|
||||
assert.Len(t, stats.Errors, 0)
|
||||
assert.Len(t, stats.Transitions, 1)
|
||||
assert.Equal(t, stats.Transitions[workspace.ID], database.WorkspaceTransitionStop)
|
||||
|
||||
// Wait for stop to complete
|
||||
updated = coderdtest.MustWorkspace(t, client, workspace.ID)
|
||||
_ = coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, updated.LatestBuild.ID)
|
||||
|
||||
// Start the workspace again
|
||||
workspace = coderdtest.MustTransitionWorkspace(t, client, workspace.ID, database.WorkspaceTransitionStop, database.WorkspaceTransitionStart)
|
||||
|
||||
// Given: the user changes their mind again and wants to enable autostop
|
||||
newTTL := 8 * time.Hour
|
||||
err = client.UpdateWorkspaceTTL(ctx, workspace.ID, codersdk.UpdateWorkspaceTTLRequest{TTLMillis: ptr.Ref(newTTL.Milliseconds())})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Then: the deadline should remain at the zero value
|
||||
updated = coderdtest.MustWorkspace(t, client, workspace.ID)
|
||||
assert.Zero(t, updated.LatestBuild.Deadline)
|
||||
|
||||
// When: the relentless onward march of time continues
|
||||
go func() {
|
||||
tickCh <- workspace.LatestBuild.Deadline.Time.Add(newTTL + time.Minute)
|
||||
close(tickCh)
|
||||
}()
|
||||
|
||||
// Then: the workspace should not stop
|
||||
stats = <-statsCh
|
||||
stats := <-statsCh
|
||||
assert.Len(t, stats.Errors, 0)
|
||||
assert.Len(t, stats.Transitions, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user