1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-31 14:35:37 -05:00

incorporate changes in router implementation

This commit is contained in:
Shelikhoo
2021-06-19 00:02:46 +01:00
parent 24a5e34ce0
commit ea5bb04acf
16 changed files with 421 additions and 985 deletions

View File

@@ -2,9 +2,11 @@ package router
import (
"testing"
"time"
)
/*
Split into multiple package, need to be tested separately
func TestSelectLeastLoad(t *testing.T) {
settings := &StrategyLeastLoadConfig{
HealthCheck: &HealthPingConfig{
@@ -13,7 +15,7 @@ func TestSelectLeastLoad(t *testing.T) {
Expected: 1,
MaxRTT: int64(time.Millisecond * time.Duration(800)),
}
strategy := NewLeastLoadStrategy(settings, nil)
strategy := NewLeastLoadStrategy(settings)
// std 40
strategy.PutResult("a", time.Millisecond*time.Duration(60))
strategy.PutResult("a", time.Millisecond*time.Duration(140))
@@ -63,7 +65,7 @@ func TestSelectLeastLoadWithCost(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
}
*/
func TestSelectLeastExpected(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
@@ -72,10 +74,10 @@ func TestSelectLeastExpected(t *testing.T) {
},
}
nodes := []*node{
{Tag: "a", applied: 100},
{Tag: "b", applied: 200},
{Tag: "c", applied: 300},
{Tag: "d", applied: 350},
{Tag: "a", RTTDeviationCost: 100},
{Tag: "b", RTTDeviationCost: 200},
{Tag: "c", RTTDeviationCost: 300},
{Tag: "d", RTTDeviationCost: 350},
}
expected := 3
ns := strategy.selectLeastLoad(nodes)
@@ -91,8 +93,8 @@ func TestSelectLeastExpected2(t *testing.T) {
},
}
nodes := []*node{
{Tag: "a", applied: 100},
{Tag: "b", applied: 200},
{Tag: "a", RTTDeviationCost: 100},
{Tag: "b", RTTDeviationCost: 200},
}
expected := 2
ns := strategy.selectLeastLoad(nodes)
@@ -108,11 +110,11 @@ func TestSelectLeastExpectedAndBaselines(t *testing.T) {
},
}
nodes := []*node{
{Tag: "a", applied: 100},
{Tag: "b", applied: 200},
{Tag: "c", applied: 250},
{Tag: "d", applied: 300},
{Tag: "e", applied: 310},
{Tag: "a", RTTDeviationCost: 100},
{Tag: "b", RTTDeviationCost: 200},
{Tag: "c", RTTDeviationCost: 250},
{Tag: "d", RTTDeviationCost: 300},
{Tag: "e", RTTDeviationCost: 310},
}
expected := 4
ns := strategy.selectLeastLoad(nodes)
@@ -128,11 +130,11 @@ func TestSelectLeastExpectedAndBaselines2(t *testing.T) {
},
}
nodes := []*node{
{Tag: "a", applied: 500},
{Tag: "b", applied: 600},
{Tag: "c", applied: 700},
{Tag: "d", applied: 800},
{Tag: "e", applied: 900},
{Tag: "a", RTTDeviationCost: 500},
{Tag: "b", RTTDeviationCost: 600},
{Tag: "c", RTTDeviationCost: 700},
{Tag: "d", RTTDeviationCost: 800},
{Tag: "e", RTTDeviationCost: 900},
}
expected := 3
ns := strategy.selectLeastLoad(nodes)
@@ -148,9 +150,9 @@ func TestSelectLeastLoadBaselines(t *testing.T) {
},
}
nodes := []*node{
{Tag: "a", applied: 100},
{Tag: "b", applied: 200},
{Tag: "c", applied: 300},
{Tag: "a", RTTDeviationCost: 100},
{Tag: "b", RTTDeviationCost: 200},
{Tag: "c", RTTDeviationCost: 300},
}
expected := 2
ns := strategy.selectLeastLoad(nodes)
@@ -166,8 +168,8 @@ func TestSelectLeastLoadBaselinesNoQualified(t *testing.T) {
},
}
nodes := []*node{
{Tag: "a", applied: 800},
{Tag: "b", applied: 1000},
{Tag: "a", RTTDeviationCost: 800},
{Tag: "b", RTTDeviationCost: 1000},
}
expected := 0
ns := strategy.selectLeastLoad(nodes)