-
Notifications
You must be signed in to change notification settings - Fork 6
feat(gc): add --snapshot LRU eviction flag #53
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02c2416
feat(gc): add --snapshot LRU eviction flag
CMGS f6b7074
rename
CMGS 9856d87
fix(gc): address 3 review nits on snapshot LRU eviction
CMGS f40d3de
chore(gc): apply /code review nits on snapshot LRU
CMGS bcfa989
fix(snapshot): async LastAccessedAt touch + finalize-time stamp on Cr…
CMGS e6d903c
fix(snapshot): drain async touches in test + cancellable gc Collect
CMGS ca3c38a
fix(snapshot): backfill SizeBytes for pre-PR records when --snapshot-…
CMGS 3516770
fix(snapshot): unblock gc backfill self-lock + revert touch to sync
CMGS 2330ad1
chore(snapshot): /code modernize + trim godocs
CMGS 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package others | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func buildGCCmd() *cobra.Command { | ||
| cmd := &cobra.Command{Use: "gc"} | ||
| cmd.Flags().Bool("snapshot", false, "") | ||
| cmd.Flags().Int("snapshot-keep", 0, "") | ||
| cmd.Flags().Duration("snapshot-age", 0, "") | ||
| cmd.Flags().String("snapshot-size", "", "") | ||
| cmd.Flags().Bool("snapshot-dry-run", false, "") | ||
| return cmd | ||
| } | ||
|
|
||
| func TestParseSnapshotPolicy_Defaults(t *testing.T) { | ||
| cmd := buildGCCmd() | ||
| if err := cmd.ParseFlags(nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| p, err := parseSnapshotPolicy(cmd) | ||
| if err != nil { | ||
| t.Fatalf("default flags: %v", err) | ||
| } | ||
| if p.Enabled { | ||
| t.Errorf("Enabled should default false") | ||
| } | ||
| } | ||
|
|
||
| func TestParseSnapshotPolicy_NegativeRejected(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| args []string | ||
| want string | ||
| }{ | ||
| {"negative keep", []string{"--snapshot", "--snapshot-keep=-1"}, "--snapshot-keep"}, | ||
| {"negative age", []string{"--snapshot", "--snapshot-age=-1h"}, "--snapshot-age"}, | ||
| {"negative size", []string{"--snapshot", "--snapshot-size=-100"}, "--snapshot-size"}, | ||
| } | ||
| for _, tt := range cases { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| cmd := buildGCCmd() | ||
| if err := cmd.ParseFlags(tt.args); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| _, err := parseSnapshotPolicy(cmd) | ||
| if err == nil { | ||
| t.Fatalf("expected error, got nil") | ||
| } | ||
| if !strings.Contains(err.Error(), tt.want) { | ||
| t.Errorf("err %q should mention %s", err, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestParseSnapshotPolicy_SubFlagRequiresSnapshot(t *testing.T) { | ||
| cases := [][]string{ | ||
| {"--snapshot-keep=5"}, | ||
| {"--snapshot-age=24h"}, | ||
| {"--snapshot-size=10GB"}, | ||
| {"--snapshot-dry-run"}, | ||
| } | ||
| for _, args := range cases { | ||
| t.Run(args[0], func(t *testing.T) { | ||
| cmd := buildGCCmd() | ||
| if err := cmd.ParseFlags(args); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| _, err := parseSnapshotPolicy(cmd) | ||
| if err == nil || !strings.Contains(err.Error(), "requires --snapshot") { | ||
| t.Errorf("want 'requires --snapshot' error, got %v", err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestParseSnapshotPolicy_HappyPath(t *testing.T) { | ||
| cmd := buildGCCmd() | ||
| if err := cmd.ParseFlags([]string{ | ||
| "--snapshot", | ||
| "--snapshot-keep=10", | ||
| "--snapshot-age=720h", | ||
| "--snapshot-size=100GB", | ||
| "--snapshot-dry-run", | ||
| }); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| p, err := parseSnapshotPolicy(cmd) | ||
| if err != nil { | ||
| t.Fatalf("happy path: %v", err) | ||
| } | ||
| if !p.Enabled || !p.DryRun || p.KeepLast != 10 || p.MaxAge == 0 || p.MaxSize == 0 { | ||
| t.Errorf("policy not populated: %+v", p) | ||
| } | ||
| } |
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.