优化压测机器人代码
This commit is contained in:
parent
10e8095c9a
commit
ef8cecd870
@ -62,3 +62,10 @@ type MessageResp struct {
|
|||||||
resp proto.Message
|
resp proto.Message
|
||||||
errdata *pb.ErrorData
|
errdata *pb.ErrorData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Pipeline struct {
|
||||||
|
Module string //模块名
|
||||||
|
Exenum int32 //执行次数
|
||||||
|
CurrNum int32 //当前已执行次数
|
||||||
|
ErrNotStop bool //遇到错误是否中断
|
||||||
|
}
|
||||||
|
@ -28,7 +28,22 @@ func (this *ModuleRobot_Chat) Receive(robot IRobot, stype string, message proto.
|
|||||||
|
|
||||||
//机器人执行流
|
//机器人执行流
|
||||||
func (this *ModuleRobot_Chat) DoPipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_Chat) DoPipeline(robot IRobot) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
usermodule *ModuleRobot_User
|
||||||
|
)
|
||||||
|
usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User)
|
||||||
|
if _, errdata = robot.SendMessage("chat", "send", &pb.ChatSendReq{
|
||||||
|
Avatar: usermodule.user.Avatar,
|
||||||
|
Uname: usermodule.user.Name,
|
||||||
|
Ulv: usermodule.user.Lv,
|
||||||
|
Channel: pb.ChatChannel_World,
|
||||||
|
Ctype: pb.ChatType_Text,
|
||||||
|
Content: fmt.Sprintf("你好!我是%s", robot.Account()),
|
||||||
|
}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package robot
|
package robot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
@ -23,7 +26,17 @@ func (this *ModuleRobot_GM) Receive(robot IRobot, stype string, message proto.Me
|
|||||||
|
|
||||||
//机器人执行流
|
//机器人执行流
|
||||||
func (this *ModuleRobot_GM) DoPipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_GM) DoPipeline(robot IRobot) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
)
|
||||||
|
if _, errdata = robot.SendMessage("gm", "cmd", &pb.GMCmdReq{Cmod: "bingo:attr,gold,1000000"}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, errdata = robot.SendMessage("gm", "cmd", &pb.GMCmdReq{Cmod: "bingo:attr,diamond,1000000"}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,31 @@ func (this *ModuleRobot_Shop) Receive(robot IRobot, stype string, message proto.
|
|||||||
|
|
||||||
//机器人执行流
|
//机器人执行流
|
||||||
func (this *ModuleRobot_Shop) DoPipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_Shop) DoPipeline(robot IRobot) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
usermodule *ModuleRobot_User
|
||||||
|
)
|
||||||
|
usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User)
|
||||||
|
if _, errdata = robot.SendMessage("shop", "getlist", &pb.ShopGetListReq{
|
||||||
|
SType: pb.ShopType_DiamondShop,
|
||||||
|
}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range this.goods[pb.ShopType_DiamondShop] {
|
||||||
|
if v.LeftBuyNum > 0 && usermodule.user.Diamond >= int64(v.Consume[0].N) {
|
||||||
|
if _, errdata = robot.SendMessage("shop", "buy", &pb.ShopBuyReq{
|
||||||
|
ShopType: pb.ShopType_DiamondShop,
|
||||||
|
Gid: v.Gid,
|
||||||
|
BuyNum: 1,
|
||||||
|
}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ type (
|
|||||||
RobotName string //机器人名称
|
RobotName string //机器人名称
|
||||||
RobotStart int32 //机器人初始下标
|
RobotStart int32 //机器人初始下标
|
||||||
RobotLog bool
|
RobotLog bool
|
||||||
Pipeline []string //执行流水线
|
Pipeline []Pipeline //执行流水线
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,8 +31,10 @@ type Robot struct {
|
|||||||
curreq string //当前请求
|
curreq string //当前请求
|
||||||
await chan *MessageResp
|
await chan *MessageResp
|
||||||
modules map[core.M_Modules]IModuleRobot
|
modules map[core.M_Modules]IModuleRobot
|
||||||
pipeline []string //执行流水线
|
cycle bool
|
||||||
|
pipeline []Pipeline //执行流水线
|
||||||
statistics []*RobotStatistics
|
statistics []*RobotStatistics
|
||||||
|
wtaskerror error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Robot) Account() string {
|
func (this *Robot) Account() string {
|
||||||
@ -246,11 +248,24 @@ func (this *Robot) run() {
|
|||||||
module IModuleRobot
|
module IModuleRobot
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
for _, v := range this.pipeline {
|
for this.cycle {
|
||||||
module = this.modules[core.M_Modules(v)]
|
this.cycle = false
|
||||||
if err = module.DoPipeline(this); err != nil {
|
for _, v := range this.pipeline {
|
||||||
log.Debug("[机器人 执行异常]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "module", Value: v}, log.Field{Key: "err", Value: err.Error()})
|
if v.CurrNum < v.Exenum {
|
||||||
break
|
module = this.modules[core.M_Modules(v.Module)]
|
||||||
|
if err = module.DoPipeline(this); err != nil {
|
||||||
|
if this.debug {
|
||||||
|
log.Debug("[机器人 执行异常]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "module", Value: v}, log.Field{Key: "err", Value: err.Error()})
|
||||||
|
}
|
||||||
|
if !v.ErrNotStop {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v.CurrNum++
|
||||||
|
if v.CurrNum < v.Exenum {
|
||||||
|
this.cycle = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.Close()
|
this.Close()
|
||||||
|
@ -65,6 +65,7 @@ func (this *robotmgrComp) createRobot(index int32) {
|
|||||||
index: index,
|
index: index,
|
||||||
account: fmt.Sprintf("%s_%d", this.module.options.RobotName, this.module.options.RobotStart+index),
|
account: fmt.Sprintf("%s_%d", this.module.options.RobotName, this.module.options.RobotStart+index),
|
||||||
serverId: this.module.options.ServerID,
|
serverId: this.module.options.ServerID,
|
||||||
|
cycle: true,
|
||||||
pipeline: this.module.options.Pipeline,
|
pipeline: this.module.options.Pipeline,
|
||||||
}
|
}
|
||||||
if err = robot.Init(this.module.options.ServerAddr, robot); err != nil {
|
if err = robot.Init(this.module.options.ServerAddr, robot); err != nil {
|
||||||
|
@ -52,6 +52,7 @@ func (this *statisticalComp) RobotFinishedTest(robot *Robot) {
|
|||||||
if this.endClientnum >= this.module.options.RobotTotalNum { //压测结束
|
if this.endClientnum >= this.module.options.RobotTotalNum { //压测结束
|
||||||
this.OutReport()
|
this.OutReport()
|
||||||
}
|
}
|
||||||
|
log.Debugf("完成测试:%s", robot.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
//输出报表
|
//输出报表
|
||||||
|
@ -19,8 +19,9 @@ func (this *apiComp) FuncActivate(session comm.IUserSession, req *pb.SysFuncActi
|
|||||||
if opencfg != nil {
|
if opencfg != nil {
|
||||||
if id := this.module.modelSys.validCond(session.GetUserId(), opencfg); id == "" { // 条件不满足
|
if id := this.module.modelSys.validCond(session.GetUserId(), opencfg); id == "" { // 条件不满足
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_OpenCondErr,
|
Code: pb.ErrorCode_OpenCondErr,
|
||||||
Title: pb.ErrorCode_OpenCondErr.ToString(),
|
Title: pb.ErrorCode_OpenCondErr.ToString(),
|
||||||
|
Message: req.Cid,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user