-
Notifications
You must be signed in to change notification settings - Fork 0
feat: retain working Lantern servers across config updates #534
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 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bfe2441
feat: retain working Lantern servers across config updates
garmr-ulfr cf16995
fix: evict hard-demoted Lantern servers regardless of config refresh
garmr-ulfr e073eff
fix: apply --limit to JSON server list and harden nil handling
garmr-ulfr 784f8f8
docs: correct stale comment after setServers rename
garmr-ulfr ac5649e
delete dead SetServers and document hard-demotion eviction`
garmr-ulfr 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
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,120 @@ | ||
| package backend | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/getlantern/radiance/servers" | ||
| ) | ||
|
|
||
| func TestExhaustionGate_AllowRateLimitsBelowGap(t *testing.T) { | ||
| prev := defaultExhaustionRefetchGap | ||
| defaultExhaustionRefetchGap = 50 * time.Millisecond | ||
| t.Cleanup(func() { defaultExhaustionRefetchGap = prev }) | ||
|
|
||
| var g exhaustionGate | ||
| require.True(t, g.allow(), "first allow must pass on a zero gate") | ||
| assert.False(t, g.allow(), "second allow inside the gap must be rate-limited") | ||
| assert.False(t, g.allow(), "third allow inside the gap must still be rate-limited") | ||
|
|
||
| time.Sleep(defaultExhaustionRefetchGap + 10*time.Millisecond) | ||
| assert.True(t, g.allow(), "allow after the gap elapses must pass again") | ||
| assert.False(t, g.allow(), "post-recovery allow must re-arm the gate") | ||
| } | ||
|
|
||
| func newTestServer(tag string, isLantern, hardDemoted bool, updatedAt time.Time) *servers.Server { | ||
| srv := &servers.Server{ | ||
| Tag: tag, | ||
| IsLantern: isLantern, | ||
| } | ||
| if hardDemoted || !updatedAt.IsZero() { | ||
| srv.SelectionHistory = &servers.SelectionHistory{ | ||
| HardDemoted: hardDemoted, | ||
| UpdatedAt: updatedAt, | ||
| } | ||
| } | ||
| return srv | ||
| } | ||
|
|
||
| func TestLanternServersToEvict(t *testing.T) { | ||
| baseTime := time.Unix(0, 0).UTC() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| existing []*servers.Server | ||
| incoming int | ||
| limit int | ||
| want []string | ||
| }{ | ||
| { | ||
| name: "evicts only hard-demoted lantern servers", | ||
| existing: []*servers.Server{ | ||
| newTestServer("demoted", true, true, baseTime), | ||
| newTestServer("working", true, false, baseTime), | ||
| newTestServer("users-demoted", false, true, baseTime), | ||
| }, | ||
| limit: 60, | ||
| want: []string{"demoted"}, | ||
| }, | ||
| { | ||
| name: "hard-demoted lantern server is evicted regardless of incoming config", | ||
| existing: []*servers.Server{ | ||
| newTestServer("demoted", true, true, baseTime), | ||
| }, | ||
| incoming: 1, | ||
| limit: 60, | ||
| want: []string{"demoted"}, | ||
| }, | ||
| { | ||
| name: "under the limit nothing is evicted", | ||
| existing: []*servers.Server{ | ||
| newTestServer("a", true, false, baseTime), | ||
| newTestServer("b", true, false, baseTime), | ||
| }, | ||
| incoming: 2, | ||
| limit: 60, | ||
| }, | ||
| { | ||
| name: "over the limit evicts oldest working servers and keeps the newest", | ||
| existing: []*servers.Server{ | ||
| newTestServer("old", true, false, baseTime.Add(1*time.Hour)), | ||
| newTestServer("mid", true, false, baseTime.Add(2*time.Hour)), | ||
| newTestServer("new", true, false, baseTime.Add(3*time.Hour)), | ||
| }, | ||
| incoming: 1, | ||
| limit: 3, | ||
| want: []string{"old"}, | ||
| }, | ||
| { | ||
| name: "incoming at the limit evicts all existing working servers", | ||
| existing: []*servers.Server{ | ||
| newTestServer("a", true, false, baseTime.Add(1*time.Hour)), | ||
| newTestServer("b", true, false, baseTime.Add(2*time.Hour)), | ||
| }, | ||
| incoming: 3, | ||
| limit: 3, | ||
| want: []string{"a", "b"}, | ||
| }, | ||
| { | ||
| name: "server with no selection history sorts oldest", | ||
| existing: []*servers.Server{ | ||
| newTestServer("no-history", true, false, time.Time{}), | ||
| newTestServer("probed", true, false, baseTime.Add(5*time.Hour)), | ||
| }, | ||
| incoming: 1, | ||
| limit: 2, | ||
| want: []string{"no-history"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| tt := tt | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := lanternServersToEvict(tt.existing, tt.incoming, tt.limit) | ||
| assert.ElementsMatch(t, tt.want, got) | ||
| }) | ||
| } | ||
| } |
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.