mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-05 04:11:59 +00:00
cmd/tailscale,net/netcheck: add debug feature to force preferred DERP
This provides an interface for a user to force a preferred DERP outcome for all future netchecks that will take precedence unless the forced region is unreachable. The option does not persist and will be lost when the daemon restarts. Updates tailscale/corp#18997 Updates tailscale/corp#24755 Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
committed by
James Tucker
parent
74069774be
commit
7f9ebc0a83
@@ -201,6 +201,7 @@ func TestAddReportHistoryAndSetPreferredDERP(t *testing.T) {
|
||||
steps []step
|
||||
homeParams *tailcfg.DERPHomeParams
|
||||
opts *GetReportOpts
|
||||
forcedDERP int // if non-zero, force this DERP to be the preferred one
|
||||
wantDERP int // want PreferredDERP on final step
|
||||
wantPrevLen int // wanted len(c.prev)
|
||||
}{
|
||||
@@ -366,12 +367,65 @@ func TestAddReportHistoryAndSetPreferredDERP(t *testing.T) {
|
||||
wantPrevLen: 2,
|
||||
wantDERP: 1, // diff is 11ms, but d2 is greater than 2/3s of d1
|
||||
},
|
||||
{
|
||||
name: "forced_two",
|
||||
steps: []step{
|
||||
{time.Second, report("d1", 2, "d2", 3)},
|
||||
{2 * time.Second, report("d1", 4, "d2", 3)},
|
||||
},
|
||||
forcedDERP: 2,
|
||||
wantPrevLen: 2,
|
||||
wantDERP: 2,
|
||||
},
|
||||
{
|
||||
name: "forced_two_unavailable",
|
||||
steps: []step{
|
||||
{time.Second, report("d1", 2, "d2", 1)},
|
||||
{2 * time.Second, report("d1", 4)},
|
||||
},
|
||||
forcedDERP: 2,
|
||||
wantPrevLen: 2,
|
||||
wantDERP: 1,
|
||||
},
|
||||
{
|
||||
name: "forced_two_no_probe_recent_activity",
|
||||
steps: []step{
|
||||
{time.Second, report("d1", 2)},
|
||||
{2 * time.Second, report("d1", 4)},
|
||||
},
|
||||
opts: &GetReportOpts{
|
||||
GetLastDERPActivity: mkLDAFunc(map[int]time.Time{
|
||||
1: startTime,
|
||||
2: startTime.Add(time.Second),
|
||||
}),
|
||||
},
|
||||
forcedDERP: 2,
|
||||
wantPrevLen: 2,
|
||||
wantDERP: 2,
|
||||
},
|
||||
{
|
||||
name: "forced_two_no_probe_no_recent_activity",
|
||||
steps: []step{
|
||||
{time.Second, report("d1", 2)},
|
||||
{PreferredDERPFrameTime + time.Second, report("d1", 4)},
|
||||
},
|
||||
opts: &GetReportOpts{
|
||||
GetLastDERPActivity: mkLDAFunc(map[int]time.Time{
|
||||
1: startTime,
|
||||
2: startTime,
|
||||
}),
|
||||
},
|
||||
forcedDERP: 2,
|
||||
wantPrevLen: 2,
|
||||
wantDERP: 1,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
fakeTime := startTime
|
||||
c := &Client{
|
||||
TimeNow: func() time.Time { return fakeTime },
|
||||
TimeNow: func() time.Time { return fakeTime },
|
||||
ForcePreferredDERP: tt.forcedDERP,
|
||||
}
|
||||
dm := &tailcfg.DERPMap{HomeParams: tt.homeParams}
|
||||
rs := &reportState{
|
||||
|
||||
Reference in New Issue
Block a user