mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
fix Process.test.go
This commit is contained in:
parent
5966c533f8
commit
c653bf1f38
@ -1,9 +1,8 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
var version = struct {
|
var version = struct {
|
||||||
time string
|
time string
|
||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-07-09 06:13:52", "ZYB-20190522USI.ubuntu", 124,
|
"2019-07-10 04:23:04", "ZYB-20190522USI.ubuntu", 135,
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -90,6 +91,7 @@ func Process(m *ctx.Message, file string, cb func(*ctx.Message, *http.Client, []
|
|||||||
}
|
}
|
||||||
}(m.Spawn())
|
}(m.Spawn())
|
||||||
}
|
}
|
||||||
|
runtime.Gosched()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
close(output)
|
close(output)
|
||||||
return nline, time.Since(begin)
|
return nline, time.Since(begin)
|
||||||
@ -228,22 +230,35 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
|
|||||||
"cost": {Name: "cost file server nroute", Help:"接口耗时测试", Form: map[string]int{"nwork": 1, "limit": 1, "nsleep": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"cost": {Name: "cost file server nroute", Help:"接口耗时测试", Form: map[string]int{"nwork": 1, "limit": 1, "nsleep": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
var success int32 = 0
|
var success int32 = 0
|
||||||
var times time.Duration
|
var times time.Duration
|
||||||
|
mu := sync.Mutex{}
|
||||||
limit := kit.Int(m.Confx("limit"))
|
limit := kit.Int(m.Confx("limit"))
|
||||||
nline, cost := Process(m, arg[0], func(msg *ctx.Message, client *http.Client, word []string, output chan []string) {
|
nline := 0
|
||||||
|
_, cost := Process(m, arg[0], func(msg *ctx.Message, client *http.Client, word []string, output chan []string) {
|
||||||
key, uri, args := word[0], word[1], word[2]
|
key, uri, args := word[0], word[1], word[2]
|
||||||
fmt.Printf("%v/%v post: %v\t%v\n", key, limit, arg[1]+uri, args)
|
for _, host := range arg[1:]{
|
||||||
|
fmt.Printf("%v/%v post: %v\t%v\n", key, limit, host+uri, args)
|
||||||
|
|
||||||
begin := time.Now()
|
begin := time.Now()
|
||||||
res, err := client.Post(arg[1]+uri, "application/json", bytes.NewReader([]byte(args)))
|
res, err := client.Post(host+uri, "application/json", bytes.NewReader([]byte(args)))
|
||||||
if res.StatusCode == http.StatusOK {
|
if res.StatusCode == http.StatusOK {
|
||||||
io.Copy(ioutil.Discard, res.Body)
|
io.Copy(ioutil.Discard, res.Body)
|
||||||
atomic.AddInt32(&success, 1)
|
atomic.AddInt32(&success, 1)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%v/%v error: %v\n", key, limit, err)
|
fmt.Printf("%v/%v error: %v\n", key, limit, err)
|
||||||
}
|
}
|
||||||
times += time.Since(begin)
|
t := time.Since(begin)
|
||||||
|
times += t
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
|
nline++
|
||||||
|
m.Add("append", "host", host)
|
||||||
|
m.Add("append", "uri", uri)
|
||||||
|
m.Add("append", "cost", t/1000000)
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
m.Sort("cost", "int_r")
|
||||||
m.Echo("\n\nnclient: %v nreq: %v success: %v time: %v average: %vms",
|
m.Echo("\n\nnclient: %v nreq: %v success: %v time: %v average: %vms",
|
||||||
m.Confx("nwork"), nline, success, cost, int(times)/int(nline)/1000000)
|
m.Confx("nwork"), nline, success, cost, int(times)/int(nline)/1000000)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user