mirror of
https://github.com/masterking32/MasterHttpRelayVPN.git
synced 2026-05-18 23:54:37 +03:00
Add multi-relay URL support with round-robin and random endpoint selection
This commit is contained in:
@@ -308,6 +308,53 @@ func TestSendWorkerTransportReuseLimitStaysWithinConfiguredRange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextRelayURLUsesRoundRobinByDefault(t *testing.T) {
|
||||
cfg := testClientConfig()
|
||||
cfg.RelayURLs = []string{
|
||||
"https://relay-a.example/relay",
|
||||
"https://relay-b.example/relay",
|
||||
"https://relay-c.example/relay",
|
||||
}
|
||||
cfg.RelayURLSelection = "round_robin"
|
||||
|
||||
client := New(cfg, nil)
|
||||
expected := []string{
|
||||
"https://relay-a.example/relay",
|
||||
"https://relay-b.example/relay",
|
||||
"https://relay-c.example/relay",
|
||||
"https://relay-a.example/relay",
|
||||
}
|
||||
|
||||
for i, want := range expected {
|
||||
if got := client.nextRelayURL(); got != want {
|
||||
t.Fatalf("iteration %d: expected %q, got %q", i, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextRelayURLRandomChoosesConfiguredRelaySet(t *testing.T) {
|
||||
cfg := testClientConfig()
|
||||
cfg.RelayURLs = []string{
|
||||
"https://relay-a.example/relay",
|
||||
"https://relay-b.example/relay",
|
||||
"https://relay-c.example/relay",
|
||||
}
|
||||
cfg.RelayURLSelection = "random"
|
||||
|
||||
client := New(cfg, nil)
|
||||
allowed := map[string]bool{
|
||||
"https://relay-a.example/relay": true,
|
||||
"https://relay-b.example/relay": true,
|
||||
"https://relay-c.example/relay": true,
|
||||
}
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
if got := client.nextRelayURL(); !allowed[got] {
|
||||
t.Fatalf("unexpected relay URL selected: %q", got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPollBatchSkipsWhenTransportBusy(t *testing.T) {
|
||||
cfg := testClientConfig()
|
||||
client := New(cfg, nil)
|
||||
|
||||
Reference in New Issue
Block a user