Merge pull request #1 from bilibili/master

fix: unit test
pull/198/head
开发者小蓝 6 years ago committed by GitHub
commit cb4008ee5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .travis.yml
  2. 15
      pkg/net/http/blademaster/server_test.go
  3. 10
      pkg/net/rpc/warden/balancer/p2c/p2c_test.go
  4. 4
      pkg/net/trace/sample_test.go
  5. 3
      pkg/stat/sys/cpu/cpu.go

@ -15,6 +15,7 @@ env:
- ZONE=sh001 - ZONE=sh001
- DEPLOY_ENV=dev - DEPLOY_ENV=dev
- DISCOVERY_NODES=127.0.0.1:7171 - DISCOVERY_NODES=127.0.0.1:7171
- HTTP_PERF=tcp://0.0.0.0:0
# Skip the install step. Don't `go get` dependencies. Only build with the code # Skip the install step. Don't `go get` dependencies. Only build with the code
# in vendor/ # in vendor/

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

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

@ -21,8 +21,8 @@ func TestProbabilitySampling(t *testing.T) {
count++ count++
} }
} }
if count < 80 || count > 120 { if count < 60 || count > 120 {
t.Errorf("expect count between 80~120 get %d", count) t.Errorf("expect count between 60~120 get %d", count)
} }
}) })
} }

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

Loading…
Cancel
Save