mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-28 21:46:37 +08:00
阶段性提交
This commit is contained in:
45
pkg/serverconfigs/scheduling/scheduling_hash_test.go
Normal file
45
pkg/serverconfigs/scheduling/scheduling_hash_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package scheduling
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHashScheduling_Next(t *testing.T) {
|
||||
s := &HashScheduling{}
|
||||
s.Add(&TestCandidate{
|
||||
Name: "a",
|
||||
Weight: 10,
|
||||
})
|
||||
s.Add(&TestCandidate{
|
||||
Name: "b",
|
||||
Weight: 10,
|
||||
})
|
||||
s.Add(&TestCandidate{
|
||||
Name: "c",
|
||||
Weight: 10,
|
||||
})
|
||||
s.Add(&TestCandidate{
|
||||
Name: "d",
|
||||
Weight: 30,
|
||||
})
|
||||
s.Start()
|
||||
|
||||
hits := map[string]uint{}
|
||||
for _, c := range s.Candidates {
|
||||
hits[c.(*TestCandidate).Name] = 0
|
||||
}
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
for i := 0; i < 1000000; i ++ {
|
||||
call := shared.NewRequestCall()
|
||||
call.Options["key"] = "192.168.1." + fmt.Sprintf("%d", rand.Int())
|
||||
|
||||
c := s.Next(call)
|
||||
hits[c.(*TestCandidate).Name] ++
|
||||
}
|
||||
t.Log(hits)
|
||||
}
|
||||
Reference in New Issue
Block a user