修复报告
This commit is contained in:
parent
4d1ca3bf95
commit
09f8cd1926
25
lib/ai.go
25
lib/ai.go
@ -74,7 +74,7 @@ func (m *myAI) Start() bool {
|
|||||||
logrus.Warn("还未设置场景")
|
logrus.Warn("还未设置场景")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
logrus.Info("测试中...")
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
m.tickets.Take()
|
m.tickets.Take()
|
||||||
@ -97,6 +97,7 @@ func (m *myAI) Start() bool {
|
|||||||
for {
|
for {
|
||||||
total := atomic.LoadUint32(&m.useCountTotal)
|
total := atomic.LoadUint32(&m.useCountTotal)
|
||||||
if total == m.config.Global.UserCountTotal {
|
if total == m.config.Global.UserCountTotal {
|
||||||
|
logrus.Info("开始生成测试报告")
|
||||||
m.MergeResult()
|
m.MergeResult()
|
||||||
m.genReport()
|
m.genReport()
|
||||||
break
|
break
|
||||||
@ -116,10 +117,10 @@ func (m *myAI) MergeResult() {
|
|||||||
defer m.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
n := make(map[int]map[string]*Statistics)
|
n := make(map[int]map[string]*Statistics)
|
||||||
for _, r := range m.robots {
|
for _, r := range m.robots {
|
||||||
if len(m.ReportMap) == 0 {
|
if len(n) == 0 {
|
||||||
m.ReportMap = r.ReportMap
|
n = r.ReportMap
|
||||||
} else {
|
} else {
|
||||||
x := m.ReportMap //已存在的
|
x := n //已存在的
|
||||||
y := r.ReportMap //将要合并的
|
y := r.ReportMap //将要合并的
|
||||||
|
|
||||||
for i, v := range x {
|
for i, v := range x {
|
||||||
@ -131,11 +132,11 @@ func (m *myAI) MergeResult() {
|
|||||||
//判断协议是否相同
|
//判断协议是否相同
|
||||||
if k == l {
|
if k == l {
|
||||||
statis := &Statistics{}
|
statis := &Statistics{}
|
||||||
statis.ElapseTotal = (a.ElapseTotal + b.ElapseTotal) / 2
|
statis.ElapseTotal = time.Duration(int64(a.ElapseTotal+b.ElapseTotal) / int64(2))
|
||||||
statis.AvgElapse = (a.AvgElapse + b.AvgElapse) / 2
|
statis.AvgElapse = time.Duration(int64(a.AvgElapse+b.AvgElapse) / int64(2))
|
||||||
statis.CallCount = a.CallCount + b.CallCount
|
statis.CallCount = (a.CallCount + b.CallCount)
|
||||||
statis.MaxElapse = (a.MaxElapse + b.MaxElapse) / 2
|
statis.MaxElapse = time.Duration(int64(a.MaxElapse+b.MaxElapse) / int64(2))
|
||||||
statis.MinElapse = (a.MinElapse + b.MinElapse) / 2
|
statis.MinElapse = time.Duration(int64(a.MinElapse+b.MinElapse) / int64(2))
|
||||||
statis.Route = a.Route
|
statis.Route = a.Route
|
||||||
statis.SceneName = a.SceneName
|
statis.SceneName = a.SceneName
|
||||||
if n[i][k] == nil {
|
if n[i][k] == nil {
|
||||||
@ -172,8 +173,8 @@ func (m *myAI) MergeResult() {
|
|||||||
func (m *myAI) genReport() {
|
func (m *myAI) genReport() {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString("测试报告\n")
|
buf.WriteString("测试报告\n")
|
||||||
buf.WriteString(fmt.Sprintf("用户总数:%d\n",
|
buf.WriteString(fmt.Sprintf("用户总数:%d 单次投放人数:%d 投放间隔时间:%ds\n",
|
||||||
m.config.Global.UserCountTotal))
|
m.config.Global.UserCountTotal, m.config.Global.UserCount, m.config.Global.IntervalS))
|
||||||
var msgs []string
|
var msgs []string
|
||||||
var i []int
|
var i []int
|
||||||
for key, _ := range m.ReportMap {
|
for key, _ := range m.ReportMap {
|
||||||
@ -199,5 +200,5 @@ func (m *myAI) genReport() {
|
|||||||
if _, err := file.WriteString(buf.String()); err != nil {
|
if _, err := file.WriteString(buf.String()); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
logrus.Debug("已生成测试报告")
|
logrus.Info("已生成测试报告")
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ func (m *Robot) syncCall() {
|
|||||||
for {
|
for {
|
||||||
scene, err := m.sceneQueue.Pop()
|
scene, err := m.sceneQueue.Pop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("err", err).Warn("所有场景执行结束")
|
logrus.WithField("err", err).Debug("所有场景执行结束")
|
||||||
m.prepareToStop()
|
m.prepareToStop()
|
||||||
// m.genReport(sceneElipseTotal)
|
// m.genReport(sceneElipseTotal)
|
||||||
return
|
return
|
||||||
@ -231,7 +231,7 @@ func (m *Robot) syncCall() {
|
|||||||
|
|
||||||
func (m *Robot) prepareToStop() {
|
func (m *Robot) prepareToStop() {
|
||||||
atomic.CompareAndSwapUint32(&m.status, STATUS_STARTED, STATUS_STOPPING)
|
atomic.CompareAndSwapUint32(&m.status, STATUS_STARTED, STATUS_STOPPING)
|
||||||
logrus.Infof("关闭结果通道...")
|
logrus.Debug("关闭结果通道...")
|
||||||
close(m.resultCh)
|
close(m.resultCh)
|
||||||
atomic.StoreUint32(&m.status, STATUS_STOPPED)
|
atomic.StoreUint32(&m.status, STATUS_STOPPED)
|
||||||
}
|
}
|
||||||
|
3
main.go
3
main.go
@ -66,10 +66,9 @@ func setupLogger() (err error) {
|
|||||||
// FullTimestamp: true,
|
// FullTimestamp: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.InfoLevel)
|
||||||
logrus.SetOutput(os.Stdout)
|
logrus.SetOutput(os.Stdout)
|
||||||
|
|
||||||
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
|
|
||||||
file, err := os.OpenFile("robot.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
file, err := os.OpenFile("robot.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
||||||
writers := []io.Writer{
|
writers := []io.Writer{
|
||||||
file,
|
file,
|
||||||
|
@ -60,7 +60,7 @@ func TestMerge(t *testing.T) {
|
|||||||
robot1.ReportMap[1] = make(map[string]*lib.Statistics)
|
robot1.ReportMap[1] = make(map[string]*lib.Statistics)
|
||||||
robot1.ReportMap[1]["user.login"] = &lib.Statistics{
|
robot1.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||||
ElapseTotal: 5,
|
ElapseTotal: 5,
|
||||||
CallCount: 1,
|
CallCount: 2,
|
||||||
AvgElapse: 1,
|
AvgElapse: 1,
|
||||||
MaxElapse: 4,
|
MaxElapse: 4,
|
||||||
MinElapse: 1,
|
MinElapse: 1,
|
||||||
@ -82,7 +82,20 @@ func TestMerge(t *testing.T) {
|
|||||||
SceneName: "登录",
|
SceneName: "登录",
|
||||||
}
|
}
|
||||||
ma.AppendRobot(robot2)
|
ma.AppendRobot(robot2)
|
||||||
|
//////
|
||||||
|
robot3 := lib.NewRobot(config)
|
||||||
|
robot3.ReportMap = make(map[int]map[string]*lib.Statistics)
|
||||||
|
robot3.ReportMap[1] = make(map[string]*lib.Statistics)
|
||||||
|
robot3.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||||
|
ElapseTotal: 8,
|
||||||
|
CallCount: 1,
|
||||||
|
AvgElapse: 3,
|
||||||
|
MaxElapse: 2,
|
||||||
|
MinElapse: 2,
|
||||||
|
Route: "user.login",
|
||||||
|
SceneName: "登录",
|
||||||
|
}
|
||||||
|
ma.AppendRobot(robot3)
|
||||||
ma.MergeResult()
|
ma.MergeResult()
|
||||||
|
|
||||||
fmt.Println(ma.ReportMap)
|
fmt.Println(ma.ReportMap)
|
||||||
|
Loading…
Reference in New Issue
Block a user