fix unit test

pull/202/head
Tony 5 years ago
parent 090d749dc4
commit 72193e3ef5
  1. 15
      pkg/net/http/blademaster/server_test.go
  2. 10
      pkg/net/rpc/warden/balancer/p2c/p2c_test.go
  3. 3
      pkg/stat/sys/cpu/cpu.go

@ -20,7 +20,6 @@ import (
var (
sonce sync.Once
SockAddr = "localhost:18080"
curEngine atomic.Value
)
@ -50,16 +49,17 @@ func setupHandler(engine *Engine) {
})
}
func startServer() {
func startServer(addr string) {
e := DefaultServer(nil)
setupHandler(e)
go e.Run(SockAddr)
go e.Run(addr)
curEngine.Store(e)
time.Sleep(time.Second)
}
func TestCriticality(t *testing.T) {
startServer()
addr := "localhost:18001"
startServer(addr)
defer shutdown()
tests := []*struct {
@ -85,7 +85,7 @@ func TestCriticality(t *testing.T) {
}
client := &http.Client{}
for _, testCase := range tests {
req, err := http.NewRequest("GET", uri(SockAddr, testCase.path), nil)
req, err := http.NewRequest("GET", uri(addr, testCase.path), nil)
assert.NoError(t, err)
req.Header.Set("x-bm-metadata-criticality", string(testCase.crtl))
resp, err := client.Do(req)
@ -98,7 +98,8 @@ func TestCriticality(t *testing.T) {
}
func TestNoneCriticality(t *testing.T) {
startServer()
addr := "localhost:18002"
startServer(addr)
defer shutdown()
tests := []*struct {
@ -124,7 +125,7 @@ func TestNoneCriticality(t *testing.T) {
}
client := &http.Client{}
for _, testCase := range tests {
req, err := http.NewRequest("GET", uri(SockAddr, testCase.path), nil)
req, err := http.NewRequest("GET", uri(addr, testCase.path), nil)
assert.NoError(t, err)
req.Header.Set("x-bm-metadata-criticality", string(testCase.crtl))
resp, err := client.Do(req)

@ -30,12 +30,12 @@ var extraDelay int64
var extraWeight uint64
func init() {
flag.IntVar(&serverNum, "snum", 5, "-snum 6")
flag.IntVar(&cliNum, "cnum", 5, "-cnum 12")
flag.IntVar(&concurrency, "concurrency", 5, "-cc 10")
flag.IntVar(&serverNum, "snum", 6, "-snum 6")
flag.IntVar(&cliNum, "cnum", 12, "-cnum 12")
flag.IntVar(&concurrency, "concurrency", 10, "-cc 10")
flag.Int64Var(&extraLoad, "exload", 3, "-exload 3")
flag.Int64Var(&extraDelay, "exdelay", 0, "-exdelay 250")
flag.Uint64Var(&extraWeight, "extraWeight", 0, "-exdelay 50")
flag.Int64Var(&extraDelay, "exdelay", 250, "-exdelay 250")
flag.Uint64Var(&extraWeight, "extraWeight", 50, "-exdelay 50")
}
type testSubConn struct {

@ -15,6 +15,7 @@ var (
usage uint64
)
// CPU is cpu stat usage.
type CPU interface {
Usage() (u uint64, e error)
Info() Info
@ -26,7 +27,7 @@ func init() {
)
stats, err = newCgroupCPU()
if err != nil {
fmt.Printf("cgroup cpu init failed(%v),switch to psutil cpu\n", err)
// fmt.Printf("cgroup cpu init failed(%v),switch to psutil cpu\n", err)
stats, err = newPsutilCPU(interval)
if err != nil {
panic(fmt.Sprintf("cgroup cpu init failed!err:=%v", err))

Loading…
Cancel
Save