修改测试报告
This commit is contained in:
parent
21c0de8ca0
commit
4fcf459413
33
lib/robot.go
33
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,9 +229,7 @@ func (m *Robot) SendResult(result *CallResult) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Robot) ShowResult() {
|
func (m *Robot) ShowResult() {
|
||||||
// statistics := &Statistics{}
|
go func() {
|
||||||
// max := statistics.MaxElapse
|
|
||||||
// min := statistics.MinElapse
|
|
||||||
routes := make(map[string]*Statistics)
|
routes := make(map[string]*Statistics)
|
||||||
for r := range m.resultCh {
|
for r := range m.resultCh {
|
||||||
head := fmt.Sprintf("%s.%s", r.MainType, r.SubType)
|
head := fmt.Sprintf("%s.%s", r.MainType, r.SubType)
|
||||||
@ -279,7 +280,21 @@ func (m *Robot) ShowResult() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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)
|
||||||
@ -157,6 +158,7 @@ func (mw *MainWindow) configContainer() {
|
|||||||
global := &storage.Global{
|
global := &storage.Global{
|
||||||
WsAddr: wsAddrEntry.Text,
|
WsAddr: wsAddrEntry.Text,
|
||||||
SId: sidEntry.Text,
|
SId: sidEntry.Text,
|
||||||
|
UserCountTotal: cast.ToUint32(userTotalEntry.Text),
|
||||||
UserCount: cast.ToUint32(userCountEntry.Text),
|
UserCount: cast.ToUint32(userCountEntry.Text),
|
||||||
TimeoutMs: cast.ToInt32(timeoutEntry.Text),
|
TimeoutMs: cast.ToInt32(timeoutEntry.Text),
|
||||||
IntervalS: cast.ToInt32(intervalEntry.Text),
|
IntervalS: cast.ToInt32(intervalEntry.Text),
|
||||||
|
Loading…
Reference in New Issue
Block a user