-
Notifications
You must be signed in to change notification settings - Fork 876
feat: allow removing deadline for running workspace #16085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DanielleMaywood
merged 5 commits into
main
from
dm-allow-disable-autostop-for-running-workspace
Jan 13, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46f6f9c
chore: remove deadline from running workspaces on ttl change
DanielleMaywood 5ed74c0
test: add tests
DanielleMaywood 7a9e872
test: remove test for old behaviour
DanielleMaywood 1698b13
chore: fix lint issues
DanielleMaywood d787abb
chore: re-add old test but refactored
DanielleMaywood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: add tests
- Loading branch information
commit 5ed74c02beb85dd2cb64f40949b36d8d7500fd7f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2394,6 +2394,89 @@ | |
}) | ||
} | ||
|
||
t.Run("ModifyAutostopWithRunningWorkspace", func(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
fromTTL *int64 | ||
toTTL *int64 | ||
afterUpdate func(t *testing.T, before, after codersdk.NullTime) | ||
}{ | ||
{ | ||
name: "RemoveAutostopRemovesDeadline", | ||
fromTTL: ptr.Ref((8 * time.Hour).Milliseconds()), | ||
toTTL: nil, | ||
afterUpdate: func(t *testing.T, before, after codersdk.NullTime) { | ||
require.NotZero(t, before) | ||
require.Zero(t, after) | ||
}, | ||
}, | ||
{ | ||
name: "AddAutostopDoesNotAddDeadline", | ||
fromTTL: nil, | ||
toTTL: ptr.Ref((8 * time.Hour).Milliseconds()), | ||
afterUpdate: func(t *testing.T, before, after codersdk.NullTime) { | ||
require.Zero(t, before) | ||
require.Zero(t, after) | ||
}, | ||
}, | ||
{ | ||
name: "IncreaseAutostopDoesNotModifyDeadline", | ||
fromTTL: ptr.Ref((4 * time.Hour).Milliseconds()), | ||
toTTL: ptr.Ref((8 * time.Hour).Milliseconds()), | ||
afterUpdate: func(t *testing.T, before, after codersdk.NullTime) { | ||
require.NotZero(t, before) | ||
require.NotZero(t, after) | ||
require.Equal(t, before, after) | ||
}, | ||
}, | ||
{ | ||
name: "DecreaseAutostopDoesNotModifyDeadline", | ||
fromTTL: ptr.Ref((8 * time.Hour).Milliseconds()), | ||
toTTL: ptr.Ref((4 * time.Hour).Milliseconds()), | ||
afterUpdate: func(t *testing.T, before, after codersdk.NullTime) { | ||
require.NotZero(t, before) | ||
require.NotZero(t, after) | ||
require.Equal(t, before, after) | ||
}, | ||
}, | ||
Comment on lines
+2424
to
+2443
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise, non-blocking: I feel like this requirement may change in future. These tests look very simple to modify in that case, so 👍 from me here |
||
} | ||
|
||
for _, testCase := range testCases { | ||
testCase := testCase | ||
|
||
t.Run(testCase.name, func(t *testing.T) { | ||
var ( | ||
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) | ||
user = coderdtest.CreateFirstUser(t, client) | ||
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) | ||
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) | ||
template = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) | ||
workspace = coderdtest.CreateWorkspace(t, client, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) { | ||
cwr.TTLMillis = testCase.fromTTL | ||
}) | ||
build = coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) | ||
) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
defer cancel() | ||
|
||
err := client.UpdateWorkspaceTTL(ctx, workspace.ID, codersdk.UpdateWorkspaceTTLRequest{ | ||
TTLMillis: testCase.toTTL, | ||
}) | ||
require.NoError(t, err) | ||
|
||
deadlineBefore := build.Deadline | ||
|
||
build, err = client.WorkspaceBuild(ctx, build.ID) | ||
require.NoError(t, err) | ||
|
||
deadlineAfter := build.Deadline | ||
|
||
testCase.afterUpdate(t, deadlineBefore, deadlineAfter) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("CustomAutostopDisabledByTemplate", func(t *testing.T) { | ||
t.Parallel() | ||
var ( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I'm thinking of this wrong, but it seems a bit weird that removing autostop removes a deadline, but adding it doesn't add one. Then again, deciding whether or not that deadline should be applied from workspace start, last activity or now is perhaps why it's not that way, oh well.. 😄