修改测试报告
This commit is contained in:
parent
21c0de8ca0
commit
4fcf459413
107
lib/robot.go
107
lib/robot.go
@ -1,7 +1,11 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -9,7 +13,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/nacos-group/nacos-sdk-go/common/logger"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"legu.airobot/pb"
|
"legu.airobot/pb"
|
||||||
@ -171,7 +174,6 @@ func (m *Robot) Start() bool {
|
|||||||
|
|
||||||
m.syncCall()
|
m.syncCall()
|
||||||
|
|
||||||
logrus.Debug("机器人运行了")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +186,7 @@ func (m *Robot) syncCall() {
|
|||||||
scene, err := m.sceneQueue.Pop()
|
scene, err := m.sceneQueue.Pop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("err", err).Error("所有场景执行结束")
|
logrus.WithField("err", err).Error("所有场景执行结束")
|
||||||
|
// m.prepareToStop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,15 +200,15 @@ func (m *Robot) syncCall() {
|
|||||||
info := scene.Info()
|
info := scene.Info()
|
||||||
logrus.WithField("t", elapsedTime.String()).Debug("场景【" + info.Name + "】执行完毕耗时统计")
|
logrus.WithField("t", elapsedTime.String()).Debug("场景【" + info.Name + "】执行完毕耗时统计")
|
||||||
//结束
|
//结束
|
||||||
m.prepareToStop()
|
// m.prepareToStop()
|
||||||
//显示场景结果
|
//显示场景结果
|
||||||
|
m.ShowResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Robot) prepareToStop() {
|
func (m *Robot) prepareToStop() {
|
||||||
atomic.CompareAndSwapUint32(&m.status, STATUS_STARTED, STATUS_STOPPING)
|
atomic.CompareAndSwapUint32(&m.status, STATUS_STARTED, STATUS_STOPPING)
|
||||||
logger.Infof("Closing result channel...")
|
logrus.Infof("关闭结果通道...")
|
||||||
close(m.resultCh)
|
close(m.resultCh)
|
||||||
atomic.StoreUint32(&m.status, STATUS_STOPPED)
|
atomic.StoreUint32(&m.status, STATUS_STOPPED)
|
||||||
}
|
}
|
||||||
@ -226,45 +229,11 @@ func (m *Robot) SendResult(result *CallResult) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Robot) ShowResult() {
|
func (m *Robot) ShowResult() {
|
||||||
// statistics := &Statistics{}
|
go func() {
|
||||||
// max := statistics.MaxElapse
|
routes := make(map[string]*Statistics)
|
||||||
// min := statistics.MinElapse
|
for r := range m.resultCh {
|
||||||
routes := make(map[string]*Statistics)
|
head := fmt.Sprintf("%s.%s", r.MainType, r.SubType)
|
||||||
for r := range m.resultCh {
|
if len(routes) == 0 {
|
||||||
head := fmt.Sprintf("%s.%s", r.MainType, r.SubType)
|
|
||||||
if len(routes) == 0 {
|
|
||||||
statis := &Statistics{
|
|
||||||
Route: head,
|
|
||||||
ElapseTotal: r.Elapse,
|
|
||||||
MaxElapse: r.Elapse,
|
|
||||||
MinElapse: r.Elapse,
|
|
||||||
CallCount: 1,
|
|
||||||
}
|
|
||||||
avg := (statis.MaxElapse + statis.MinElapse) / 2
|
|
||||||
statis.AvgElapse = avg
|
|
||||||
routes[head] = statis
|
|
||||||
} else {
|
|
||||||
if route, ok := routes[head]; ok {
|
|
||||||
max := route.MaxElapse
|
|
||||||
min := route.MinElapse
|
|
||||||
if r.Elapse > max {
|
|
||||||
max = r.Elapse
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Elapse < min {
|
|
||||||
min = r.Elapse
|
|
||||||
}
|
|
||||||
statis := &Statistics{
|
|
||||||
Route: head,
|
|
||||||
ElapseTotal: route.ElapseTotal + r.Elapse,
|
|
||||||
MaxElapse: max,
|
|
||||||
MinElapse: min,
|
|
||||||
CallCount: route.CallCount + 1,
|
|
||||||
}
|
|
||||||
avg := (statis.MaxElapse + statis.MinElapse) / 2
|
|
||||||
statis.AvgElapse = avg
|
|
||||||
routes[head] = statis
|
|
||||||
} else {
|
|
||||||
statis := &Statistics{
|
statis := &Statistics{
|
||||||
Route: head,
|
Route: head,
|
||||||
ElapseTotal: r.Elapse,
|
ElapseTotal: r.Elapse,
|
||||||
@ -275,11 +244,57 @@ func (m *Robot) ShowResult() {
|
|||||||
avg := (statis.MaxElapse + statis.MinElapse) / 2
|
avg := (statis.MaxElapse + statis.MinElapse) / 2
|
||||||
statis.AvgElapse = avg
|
statis.AvgElapse = avg
|
||||||
routes[head] = statis
|
routes[head] = statis
|
||||||
|
} else {
|
||||||
|
if route, ok := routes[head]; ok {
|
||||||
|
max := route.MaxElapse
|
||||||
|
min := route.MinElapse
|
||||||
|
if r.Elapse > max {
|
||||||
|
max = r.Elapse
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Elapse < min {
|
||||||
|
min = r.Elapse
|
||||||
|
}
|
||||||
|
statis := &Statistics{
|
||||||
|
Route: head,
|
||||||
|
ElapseTotal: route.ElapseTotal + r.Elapse,
|
||||||
|
MaxElapse: max,
|
||||||
|
MinElapse: min,
|
||||||
|
CallCount: route.CallCount + 1,
|
||||||
|
}
|
||||||
|
avg := (statis.MaxElapse + statis.MinElapse) / 2
|
||||||
|
statis.AvgElapse = avg
|
||||||
|
routes[head] = statis
|
||||||
|
} else {
|
||||||
|
statis := &Statistics{
|
||||||
|
Route: head,
|
||||||
|
ElapseTotal: r.Elapse,
|
||||||
|
MaxElapse: r.Elapse,
|
||||||
|
MinElapse: r.Elapse,
|
||||||
|
CallCount: 1,
|
||||||
|
}
|
||||||
|
avg := (statis.MaxElapse + statis.MinElapse) / 2
|
||||||
|
statis.AvgElapse = avg
|
||||||
|
routes[head] = statis
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//TODO 将统计结果写入文件
|
// 将统计结果写入文件
|
||||||
|
var msgs []string
|
||||||
|
for k, v := range routes {
|
||||||
|
msgs = append(msgs, fmt.Sprintf("协议:%s 调用次数:%d 总耗时:%v 平均耗时:%v 最大耗时:%v 最小耗时:%v",
|
||||||
|
k, v.CallCount, v.ElapseTotal.String(), v.AvgElapse.String(), v.MaxElapse.String(), v.MinElapse.String()))
|
||||||
|
}
|
||||||
|
record := strings.Join(msgs, "\n")
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteString("测试报告\n")
|
||||||
|
buf.WriteString(record)
|
||||||
|
if err := ioutil.WriteFile(filepath.Join("./", "report.txt"), buf.Bytes(), fs.ModePerm); err != nil {
|
||||||
|
logrus.WithField("err", err).Error("测试报告")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Robot) printIgnoredResult(result *CallResult, cause string) {
|
func (m *Robot) printIgnoredResult(result *CallResult, cause string) {
|
||||||
|
@ -143,6 +143,7 @@ func (mw *MainWindow) configContainer() {
|
|||||||
loadForm := func() {
|
loadForm := func() {
|
||||||
wsAddrEntry.Text = config.WsAddr
|
wsAddrEntry.Text = config.WsAddr
|
||||||
sidEntry.Text = config.SId
|
sidEntry.Text = config.SId
|
||||||
|
userTotalEntry.Text = cast.ToString(config.UserCountTotal)
|
||||||
userCountEntry.Text = cast.ToString(config.UserCount)
|
userCountEntry.Text = cast.ToString(config.UserCount)
|
||||||
timeoutEntry.Text = cast.ToString(config.TimeoutMs)
|
timeoutEntry.Text = cast.ToString(config.TimeoutMs)
|
||||||
intervalEntry.Text = cast.ToString(config.IntervalS)
|
intervalEntry.Text = cast.ToString(config.IntervalS)
|
||||||
@ -155,11 +156,12 @@ func (mw *MainWindow) configContainer() {
|
|||||||
saveBtn := widget.NewButtonWithIcon("保存", theme.DocumentSaveIcon(), nil)
|
saveBtn := widget.NewButtonWithIcon("保存", theme.DocumentSaveIcon(), nil)
|
||||||
saveBtn.OnTapped = func() {
|
saveBtn.OnTapped = func() {
|
||||||
global := &storage.Global{
|
global := &storage.Global{
|
||||||
WsAddr: wsAddrEntry.Text,
|
WsAddr: wsAddrEntry.Text,
|
||||||
SId: sidEntry.Text,
|
SId: sidEntry.Text,
|
||||||
UserCount: cast.ToUint32(userCountEntry.Text),
|
UserCountTotal: cast.ToUint32(userTotalEntry.Text),
|
||||||
TimeoutMs: cast.ToInt32(timeoutEntry.Text),
|
UserCount: cast.ToUint32(userCountEntry.Text),
|
||||||
IntervalS: cast.ToInt32(intervalEntry.Text),
|
TimeoutMs: cast.ToInt32(timeoutEntry.Text),
|
||||||
|
IntervalS: cast.ToInt32(intervalEntry.Text),
|
||||||
}
|
}
|
||||||
mw.config.Global = global
|
mw.config.Global = global
|
||||||
if err := mw.storage.StoreConfig(mw.config); err != nil {
|
if err := mw.storage.StoreConfig(mw.config); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user