Merge branch 'master' of http://git.legu.cc/zhaochangyuan/airobot
This commit is contained in:
commit
5ae298303b
28
lib/ai.go
28
lib/ai.go
@ -94,12 +94,14 @@ func (m *myAI) Start() bool {
|
||||
}()
|
||||
|
||||
go func() {
|
||||
start := time.Now()
|
||||
for {
|
||||
total := atomic.LoadUint32(&m.useCountTotal)
|
||||
if total == m.config.Global.UserCountTotal {
|
||||
elipse := time.Since(start)
|
||||
logrus.Info("开始生成测试报告")
|
||||
m.MergeResult()
|
||||
m.genReport()
|
||||
m.genReport(elipse)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -132,11 +134,19 @@ func (m *myAI) MergeResult() {
|
||||
//判断协议是否相同
|
||||
if k == l {
|
||||
statis := &Statistics{}
|
||||
statis.ElapseTotal = time.Duration(int64(a.ElapseTotal+b.ElapseTotal) / int64(2))
|
||||
statis.ElapseTotal = time.Duration(int64(a.ElapseTotal + b.ElapseTotal))
|
||||
statis.AvgElapse = time.Duration(int64(a.AvgElapse+b.AvgElapse) / int64(2))
|
||||
statis.CallCount = (a.CallCount + b.CallCount)
|
||||
statis.MaxElapse = time.Duration(int64(a.MaxElapse+b.MaxElapse) / int64(2))
|
||||
statis.MinElapse = time.Duration(int64(a.MinElapse+b.MinElapse) / int64(2))
|
||||
max := a.MaxElapse
|
||||
if max < b.MaxElapse {
|
||||
max = b.MaxElapse
|
||||
}
|
||||
statis.MaxElapse = max
|
||||
min := a.MinElapse
|
||||
if min > b.MinElapse {
|
||||
min = b.MinElapse
|
||||
}
|
||||
statis.MinElapse = min
|
||||
statis.Route = a.Route
|
||||
statis.SceneName = a.SceneName
|
||||
if n[i][k] == nil {
|
||||
@ -170,11 +180,7 @@ func (m *myAI) MergeResult() {
|
||||
m.ReportMap = n
|
||||
}
|
||||
|
||||
func (m *myAI) genReport() {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("测试报告\n")
|
||||
buf.WriteString(fmt.Sprintf("用户总数:%d 单次投放人数:%d 投放间隔时间:%ds\n",
|
||||
m.config.Global.UserCountTotal, m.config.Global.UserCount, m.config.Global.IntervalS))
|
||||
func (m *myAI) genReport(elipse time.Duration) {
|
||||
var msgs []string
|
||||
var i []int
|
||||
for key, _ := range m.ReportMap {
|
||||
@ -188,6 +194,10 @@ func (m *myAI) genReport() {
|
||||
}
|
||||
}
|
||||
record := strings.Join(msgs, "\n")
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("测试报告\n")
|
||||
buf.WriteString(fmt.Sprintf("用户总数:%d 单次投放人数:%d 投放间隔时间:%ds 共计时间:%s\n",
|
||||
m.config.Global.UserCountTotal, m.config.Global.UserCount, m.config.Global.IntervalS, elipse.String()))
|
||||
buf.WriteString(record)
|
||||
buf.WriteString("\n------------------------------------------------------------------------------------------------------\n")
|
||||
// logrus.WithField("res", buf.String()).Debug("报告内容")
|
||||
|
14
lib/robot.go
14
lib/robot.go
@ -43,7 +43,7 @@ type Robot struct {
|
||||
config *storage.Config //配置
|
||||
resultCh chan *CallResult //请求结果通道
|
||||
sceneResultCh chan *CallResult //场景结果通道
|
||||
ReportMap map[int]map[string]*Statistics //测试报告 key1:场景 key2:协议
|
||||
ReportMap map[int]map[string]*Statistics //测试报告 key1:场景序号 key2:协议
|
||||
elipseTotal time.Duration
|
||||
}
|
||||
|
||||
@ -146,8 +146,15 @@ func (a *Robot) SetScenes(scenes []IScene) {
|
||||
for _, v := range scenes {
|
||||
info := v.Info()
|
||||
if conf.Name == info.Name {
|
||||
a.sceneQueue.Add(v)
|
||||
continue
|
||||
if conf.Loop == 0 || conf.Loop == 1 {
|
||||
a.sceneQueue.Add(v)
|
||||
continue
|
||||
} else if conf.Loop > 1 {
|
||||
for i := int32(0); i < conf.Loop; i++ {
|
||||
a.sceneQueue.Add(v)
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,7 +215,6 @@ func (m *Robot) syncCall() {
|
||||
if err != nil {
|
||||
logrus.WithField("err", err).Debug("所有场景执行结束")
|
||||
m.prepareToStop()
|
||||
// m.genReport(sceneElipseTotal)
|
||||
return
|
||||
}
|
||||
m.scene = scene
|
||||
|
2
main.go
2
main.go
@ -66,7 +66,7 @@ func setupLogger() (err error) {
|
||||
// FullTimestamp: true,
|
||||
})
|
||||
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
logrus.SetOutput(os.Stdout)
|
||||
|
||||
file, err := os.OpenFile("robot.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
||||
|
@ -11,8 +11,8 @@ type Config struct {
|
||||
}
|
||||
|
||||
type Global struct {
|
||||
UserCount uint32 `json:"UserCount,omitempty"` //用户数(每次压入的数量)
|
||||
UserCountTotal uint32 `json:"UserCountTotal,omitempty"` //用户总数(压入的总数)
|
||||
UserCount uint32 `json:"UserCount,omitempty"` //用户数(每次压入的数量)
|
||||
UserCountTotal uint32 `json:"UserCountTotal,omitempty"` //用户总数(压入的总数)
|
||||
SId string `json:"sid,omitempty"` //区服ID
|
||||
WsAddr string `json:"wsAddr,omitempty"` //websocket addr
|
||||
IntervalS int32 `json:"intervalS,omitempty"` //间隔时间s(每次压入用户的间隔时间)
|
||||
@ -26,6 +26,7 @@ type Scene struct {
|
||||
Callers []*Caller `json:"callers,omitempty"` //调用器列表
|
||||
Status uint32 `json:"status,omitempty"` //是否启用 默认0未启用 1是启用
|
||||
Num int `json:"num,omitempty"` //顺序号
|
||||
Loop int32 `json:"loop,omitempty"` //循环次数
|
||||
}
|
||||
|
||||
type Caller struct {
|
||||
|
@ -61,9 +61,9 @@ func TestMerge(t *testing.T) {
|
||||
robot1.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||
ElapseTotal: 5,
|
||||
CallCount: 2,
|
||||
AvgElapse: 1,
|
||||
AvgElapse: 2,
|
||||
MaxElapse: 4,
|
||||
MinElapse: 1,
|
||||
MinElapse: 2,
|
||||
Route: "user.login",
|
||||
SceneName: "登录",
|
||||
}
|
||||
@ -75,9 +75,9 @@ func TestMerge(t *testing.T) {
|
||||
robot2.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||
ElapseTotal: 7,
|
||||
CallCount: 1,
|
||||
AvgElapse: 1,
|
||||
AvgElapse: 3,
|
||||
MaxElapse: 5,
|
||||
MinElapse: 2,
|
||||
MinElapse: 4,
|
||||
Route: "user.login",
|
||||
SceneName: "登录",
|
||||
}
|
||||
@ -89,15 +89,30 @@ func TestMerge(t *testing.T) {
|
||||
robot3.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||
ElapseTotal: 8,
|
||||
CallCount: 1,
|
||||
AvgElapse: 3,
|
||||
MaxElapse: 2,
|
||||
MinElapse: 2,
|
||||
AvgElapse: 2,
|
||||
MaxElapse: 6,
|
||||
MinElapse: 3,
|
||||
Route: "user.login",
|
||||
SceneName: "登录",
|
||||
}
|
||||
ma.AppendRobot(robot3)
|
||||
ma.MergeResult()
|
||||
|
||||
robot4 := lib.NewRobot(config)
|
||||
robot4.ReportMap = make(map[int]map[string]*lib.Statistics)
|
||||
robot4.ReportMap[1] = make(map[string]*lib.Statistics)
|
||||
robot4.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||
ElapseTotal: 8,
|
||||
CallCount: 1,
|
||||
AvgElapse: 2,
|
||||
MaxElapse: 8,
|
||||
MinElapse: 2,
|
||||
Route: "user.login",
|
||||
SceneName: "登录",
|
||||
}
|
||||
ma.AppendRobot(robot4)
|
||||
ma.MergeResult()
|
||||
|
||||
fmt.Println(ma.ReportMap)
|
||||
for i, v := range ma.ReportMap {
|
||||
fmt.Println(i)
|
||||
|
@ -611,7 +611,7 @@ func (mw *MainWindow) newSceneContainer() {
|
||||
//场景按钮
|
||||
addSceneBtn := widget.NewButtonWithIcon("添加场景", theme.ContentAddIcon(), nil)
|
||||
deleSceneBtn := widget.NewButtonWithIcon("删除场景", theme.DeleteIcon(), nil)
|
||||
setNumBtn := widget.NewButtonWithIcon("设置序号", theme.ListIcon(), nil)
|
||||
setBtn := widget.NewButtonWithIcon("场景配置", theme.ListIcon(), nil)
|
||||
|
||||
//search
|
||||
searchEntry := widget.NewEntry()
|
||||
@ -642,7 +642,7 @@ func (mw *MainWindow) newSceneContainer() {
|
||||
if len(selectedSceneList.CachedList.Items) == 0 {
|
||||
dynamic = container.NewCenter(widget.NewLabel("还没有选择任何场景"))
|
||||
} else {
|
||||
dynamic = container.NewBorder(container.NewHBox(setNumBtn, deleSceneBtn, layout.NewSpacer()), nil, nil, nil, selectedSceneList.ListWidget)
|
||||
dynamic = container.NewBorder(container.NewHBox(setBtn, deleSceneBtn, layout.NewSpacer()), nil, nil, nil, selectedSceneList.ListWidget)
|
||||
}
|
||||
}
|
||||
|
||||
@ -729,8 +729,8 @@ func (mw *MainWindow) newSceneContainer() {
|
||||
}
|
||||
}
|
||||
|
||||
// 设置序号事件
|
||||
setNumBtn.OnTapped = func() {
|
||||
// 场景配置事件
|
||||
setBtn.OnTapped = func() {
|
||||
selId := selectedSceneList.SelectedId()
|
||||
if selId == "" {
|
||||
ShowTip("请选择一个场景")
|
||||
@ -739,8 +739,12 @@ func (mw *MainWindow) newSceneContainer() {
|
||||
sceneNumEntry := widget.NewEntry()
|
||||
sceneNumEntry.Text = "0"
|
||||
|
||||
sceneLoopEntry := widget.NewEntry()
|
||||
sceneLoopEntry.Text = "1"
|
||||
|
||||
sceneItems := []*widget.FormItem{
|
||||
widget.NewFormItem("顺序号", sceneNumEntry),
|
||||
widget.NewFormItem("执行次数", sceneLoopEntry),
|
||||
}
|
||||
|
||||
// 加载
|
||||
@ -752,15 +756,25 @@ func (mw *MainWindow) newSceneContainer() {
|
||||
}
|
||||
if sceneConf != nil {
|
||||
sceneNumEntry.Text = cast.ToString(sceneConf.Num)
|
||||
if sceneConf.Loop == 0 {
|
||||
sceneLoopEntry.Text = "1"
|
||||
} else {
|
||||
sceneLoopEntry.Text = cast.ToString(sceneConf.Loop)
|
||||
}
|
||||
}
|
||||
|
||||
editSceneWin := dialog.NewForm("编辑场景序号", "确定", "取消", sceneItems, func(b bool) {
|
||||
if !b {
|
||||
return
|
||||
}
|
||||
if cast.ToInt(sceneNumEntry.Text) < 0 {
|
||||
ShowTip("顺序号必须大于0")
|
||||
return
|
||||
}
|
||||
for _, item := range mw.config.Scenes {
|
||||
if item.ID == selId {
|
||||
item.Num = cast.ToInt(sceneNumEntry.Text)
|
||||
item.Loop = cast.ToInt32(sceneLoopEntry.Text)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user