优化测试请求2

This commit is contained in:
zhaocy 2022-07-13 19:01:47 +08:00
parent 875285034f
commit 4c18c50d3d
5 changed files with 38 additions and 18 deletions

View File

@ -91,7 +91,7 @@ var (
enabled: true, enabled: true,
} }
tcs = append(tcs, tc) tcs = append(tcs, tc)
robot.addTestCaseAndReq(tcs) robot.addBuilders(tcs)
} }
}, },

View File

@ -45,7 +45,7 @@ var (
} }
tcs = append(tcs, tc) tcs = append(tcs, tc)
} }
robot.addTestCaseAndReq(tcs) robot.addBuilders(tcs)
} }
}, },

View File

@ -60,11 +60,11 @@ func (r *Robot) AccountLogin() {
req: &pb.UserCreateReq{ //设置请求参数 req: &pb.UserCreateReq{ //设置请求参数
NickName: nick, NickName: nick,
}, },
rsp: &pb.UserCreateResp{}, rsp: &pb.UserCreateResp{},
enabled: true, // enabled: true,
} }
tcs = append(tcs, tc) tcs = append(tcs, tc)
r.addTestCaseAndReq(tcs) r.addBuilders(tcs)
} }
}, },

View File

@ -24,8 +24,8 @@ type Robot struct {
user *pb.DBUser user *pb.DBUser
builderMap map[string]*TestCase builderMap map[string]*TestCase
// linkCase *LinkCase // linkCase *LinkCase
wg sync.WaitGroup wg sync.WaitGroup
reqCh chan string //请求通道uuid // reqCh chan string //请求通道uuid
// rspCh chan string //响应通道uuid // rspCh chan string //响应通道uuid
} }
@ -38,7 +38,7 @@ func NewRobot(opts *Options) *Robot {
ws: ws, ws: ws,
opts: opts, opts: opts,
builderMap: make(map[string]*TestCase), builderMap: make(map[string]*TestCase),
reqCh: make(chan string, 1), // reqCh: make(chan string, 1),
// rspCh: make(chan string, 10), // rspCh: make(chan string, 10),
} }
@ -122,7 +122,7 @@ func (r *Robot) handleReq() {
continue continue
} }
b.requested = true b.requested = true
r.reqCh <- b.id // r.reqCh <- b.id
} }
} }
} }
@ -133,18 +133,39 @@ func (r *Robot) addTestCaseAndReq(tcs []*TestCase) {
r.handleReq() r.handleReq()
} }
//处理响应 //错误通知处理
func (r *Robot) handleRsp(msg *pb.UserMessage) { func (r *Robot) handleNotify(msg *pb.UserMessage) {
uuid := <-r.reqCh if msg.MainType == "notify" && msg.SubType == "errornotify" {
if uuid == "" { rsp := &pb.NotifyErrorNotifyPush{}
log.Printf("[%v.%v] uuid is empty", msg.MainType, msg.SubType) if !comm.ProtoUnmarshal(msg, rsp) {
return
}
printReply(msg, &TestCase{
desc: "错误通知",
mainType: comm.MainTypeNotify,
subType: comm.SubTypeErrorNotify,
rsp: rsp,
enabled: true,
})
return return
} }
if v, ok := r.builderMap[uuid]; ok { }
//处理响应
func (r *Robot) handleRsp(msg *pb.UserMessage) {
r.handleNotify(msg)
// uuid := <-r.reqCh
// if uuid == "" {
// log.Printf("[%v.%v] uuid is empty", msg.MainType, msg.SubType)
// return
// }
// if v, ok := r.builderMap[uuid]; ok {
for _, v := range r.builderMap {
if v.enabled && if v.enabled &&
(msg.MainType == v.mainType && (msg.MainType == v.mainType &&
msg.SubType == v.subType) && msg.SubType == v.subType) &&
v.requested { v.requested {
if !comm.ProtoUnmarshal(msg, v.rsp) { if !comm.ProtoUnmarshal(msg, v.rsp) {
return return
} }
@ -183,6 +204,7 @@ func (r *Robot) loginCallback(rsp proto.Message) {
if lr.Data != nil { if lr.Data != nil {
r.user = lr.Data r.user = lr.Data
r.onUserLoaded() r.onUserLoaded()
r.handleReq()
} else { } else {
//请求Http接口模拟创建新账号 //请求Http接口模拟创建新账号
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId)) r.AccountRegister(r.opts.Account, int32(r.opts.ServerId))
@ -268,8 +290,6 @@ func traceFunc(module string, funcName string, uid string, funcArgs interface{})
//在这里添加玩家成功登录以后的测试方法 //在这里添加玩家成功登录以后的测试方法
//次方法在用户登录成功后调用 //次方法在用户登录成功后调用
func (r *Robot) onUserLoaded() { func (r *Robot) onUserLoaded() {
//notify
r.RunNotify()
//user //user
r.RunUser() r.RunUser()
//hero //hero

View File

@ -33,7 +33,7 @@ var (
StoryId: 1, StoryId: 1,
}, },
rsp: &pb.StoryChallengeResp{}, rsp: &pb.StoryChallengeResp{},
enabled: true, // enabled: true,
}, },
} }
) )