Files
EdgeCommon/pkg/serverconfigs/schedulingconfigs/scheduling_hash_test.go

46 lines
787 B
Go
Raw Normal View History

2020-09-15 14:44:38 +08:00
package schedulingconfigs
2020-09-13 19:27:47 +08:00
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)
}