修改属性key

This commit is contained in:
zhaocy 2022-07-01 18:49:48 +08:00
parent 435d901936
commit 78ee56deda
10 changed files with 179 additions and 51 deletions

View File

@ -11,11 +11,12 @@ var (
friendBuilders = []*TestCase{ friendBuilders = []*TestCase{
{ {
//list //list
Desc: "好友列表",
mainType: string(comm.ModuleFriend), mainType: string(comm.ModuleFriend),
subType: friend.FriendSubTypeList, subType: friend.FriendSubTypeList,
req: &pb.FriendListReq{}, req: &pb.FriendListReq{},
rsp: &pb.FriendListRsp{}, rsp: &pb.FriendListRsp{},
// enabled: true, enabled: true,
}, { }, {
//blacklist //blacklist
mainType: string(comm.ModuleFriend), mainType: string(comm.ModuleFriend),
@ -29,7 +30,8 @@ var (
req: &pb.FriendSearchReq{ req: &pb.FriendSearchReq{
NickName: "", //设置测试参数 NickName: "", //设置测试参数
}, },
rsp: &pb.FriendSearchRsp{}, rsp: &pb.FriendSearchRsp{},
enabled: true,
}, { }, {
//apply //apply
mainType: string(comm.ModuleFriend), mainType: string(comm.ModuleFriend),
@ -62,8 +64,8 @@ var (
req: &pb.FriendBlackAddReq{ req: &pb.FriendBlackAddReq{
FriendId: "0_62be9f40f67327fb53039b70", FriendId: "0_62be9f40f67327fb53039b70",
}, },
rsp: &pb.FriendBlackAddRsp{}, rsp: &pb.FriendBlackAddRsp{},
enabled: true, // enabled: true,
}, { }, {
//delblack //delblack
mainType: string(comm.ModuleFriend), mainType: string(comm.ModuleFriend),

View File

@ -13,7 +13,7 @@ var (
//hero //hero
heroBuilders = []*TestCase{ heroBuilders = []*TestCase{
{ {
desc: "英雄列表", Desc: "英雄列表",
mainType: string(comm.ModuleHero), mainType: string(comm.ModuleHero),
subType: hero.HeroSubTypeList, subType: hero.HeroSubTypeList,
req: &pb.HeroListReq{}, req: &pb.HeroListReq{},

View File

@ -1,26 +0,0 @@
package robot
type CaseNode struct {
testCase TestCase //用例名
next *CaseNode //测试用例
}
type LinkCase struct {
head *CaseNode
}
func NewLinkCase() *LinkCase {
return &LinkCase{}
}
func (this *LinkCase) isEmpty() bool {
return this.head == nil
}
func (this *LinkCase) append(testCase *TestCase) {
newNode := &CaseNode{testCase: *testCase}
if this.isEmpty() {
this.head = newNode
}
}

95
cmd/robot/linkcase.go Normal file
View File

@ -0,0 +1,95 @@
package robot
import (
"fmt"
"log"
)
type CaseNode struct {
testCase *TestCase //用例名
Next *CaseNode //测试用例
}
type LinkCase struct {
Head *CaseNode
force bool
}
func NewLinkCase() *LinkCase {
return &LinkCase{}
}
func NewDefault(testCast *TestCase) *LinkCase {
return &LinkCase{
force: true,
Head: &CaseNode{testCase: testCast},
}
}
func (this *LinkCase) isEmpty() bool {
return this.Head == nil
}
func (this *LinkCase) lastNode() *CaseNode {
cur := this.Head
for cur.Next != nil {
cur = cur.Next
}
return cur
}
//尾部追加
func (this *LinkCase) Append(testCase *TestCase) {
newNode := &CaseNode{testCase: testCase}
if this.isEmpty() {
this.Head = newNode
} else {
this.lastNode().Next = newNode
}
}
//头部添加
func (this *LinkCase) Unshift(testCase *TestCase) {
if this.force {
log.Fatal("use `NewLinkCase` method create link if you want to use `Unshift` opt")
return
}
newNode := &CaseNode{testCase: testCase}
newNode.Next = this.Head
this.Head = newNode
}
func (this *LinkCase) length() int {
cur := this.Head
count := 0
for cur.Next != nil {
cur = cur.Next
count++
}
return count
}
func (this *LinkCase) Insert(index int, testCase *TestCase) {
if this.force {
log.Fatal("use `NewLinkCase` method create link if you want to use `Insert` opt")
return
}
if index < 0 {
this.Unshift(testCase)
} else if index > this.length() {
this.Append(testCase)
} else {
preNode := this.Head
count := 0
for count < index-1 {
preNode = preNode.Next
count++
}
newNode := &CaseNode{testCase: testCase, Next: preNode.Next}
preNode.Next = newNode
}
}
func (this *CaseNode) String() string {
return fmt.Sprintf("value=%v", this.testCase.Desc)
}

View File

@ -0,0 +1,32 @@
package robot_test
import (
"fmt"
"go_dreamfactory/cmd/robot"
"sync"
"testing"
)
func TestJob(t *testing.T) {
// link := robot.NewLinkCase()
link := robot.NewDefault(&robot.TestCase{Desc: "login"})
link.Append(&robot.TestCase{Desc: "aa"})
// link.Append(&robot.TestCase{Desc: "bb"})
// link.Unshift(&robot.TestCase{Desc: "cc"})
// link.Unshift(&robot.TestCase{Desc: "dd"})
// link.Insert(1, &robot.TestCase{Desc: "ee"})
cur := link.Head
for cur != nil {
fmt.Println(cur)
cur = cur.Next
}
}
func TestGJo(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
}

View File

@ -9,6 +9,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"sync"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -20,7 +21,10 @@ type Robot struct {
ws *websocket.Conn ws *websocket.Conn
opts *Options opts *Options
user *pb.DBUser user *pb.DBUser
builders []*TestCase builders []*TestCase //测试用例
linkCase *LinkCase //测试用例链,适应于用例跑批
wg sync.WaitGroup
} }
func NewRobot(opts *Options) *Robot { func NewRobot(opts *Options) *Robot {
@ -29,8 +33,9 @@ func NewRobot(opts *Options) *Robot {
log.Fatal(err) log.Fatal(err)
} }
r := &Robot{ r := &Robot{
ws: ws, ws: ws,
opts: opts, opts: opts,
linkCase: NewLinkCase(),
} }
return r return r
@ -50,7 +55,7 @@ func (r *Robot) Run() {
//处理响应 //处理响应
go func() { go func() {
for { for {
var msg *pb.UserMessage = &pb.UserMessage{} var msg *pb.UserMessage = &pb.UserMessage{}
_, data, err := r.ws.ReadMessage() _, data, err := r.ws.ReadMessage()
if err != nil { if err != nil {
@ -64,11 +69,12 @@ func (r *Robot) Run() {
} }
}() }()
select {} // select {}
r.wg.Wait()
} }
type TestCase struct { type TestCase struct {
desc string Desc string
mainType string mainType string
subType string subType string
req proto.Message req proto.Message
@ -91,6 +97,7 @@ func (r *Robot) addBuilders(builders []*TestCase) {
func (r *Robot) handleReq() { func (r *Robot) handleReq() {
for _, b := range r.builders { for _, b := range r.builders {
if b.req != nil && !b.requested { if b.req != nil && !b.requested {
r.wg.Add(1)
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
b.requested = true b.requested = true
b.start = time.Now() b.start = time.Now()
@ -115,7 +122,7 @@ func (r *Robot) handleRsp(msg *pb.UserMessage) {
if b.print == nil { if b.print == nil {
printReply(msg, b) printReply(msg, b)
} else { } else {
fmt.Printf("===== %s [%s.%s] =====\n", b.desc, msg.MainType, msg.SubType) fmt.Printf("===== %s [%s.%s] =====\n", b.Desc, msg.MainType, msg.SubType)
b.print(b.rsp) b.print(b.rsp)
fmt.Println("==============================") fmt.Println("==============================")
} }
@ -127,6 +134,8 @@ func (r *Robot) handleRsp(msg *pb.UserMessage) {
r.builders = append(r.builders[:i], r.builders[i+1:]...) r.builders = append(r.builders[:i], r.builders[i+1:]...)
} }
} }
r.wg.Done()
} }
} }
@ -201,7 +210,7 @@ func (r *Robot) AccountRegister(account string, sid int32) {
//登录 //登录
var user_builders = []*TestCase{ var user_builders = []*TestCase{
{ {
desc: "登录", Desc: "登录",
mainType: "user", mainType: "user",
subType: "login", subType: "login",
req: &pb.UserLoginReq{ req: &pb.UserLoginReq{
@ -226,9 +235,9 @@ func printReply(msg *pb.UserMessage, builder *TestCase) {
} else { } else {
tt = time.Since(builder.start) tt = time.Since(builder.start)
} }
log.Printf("rsp %s [%v] [%s.%s] [%v:%v]", builder.desc, tt, m.ReqMainType, m.ReqSubType, int32(m.Code), m.Data) log.Printf("rsp %s [%v] [%s.%s] [%v:%v]", builder.Desc, tt, m.ReqMainType, m.ReqSubType, int32(m.Code), m.Data)
} else { } else {
log.Printf("rsp %s [%v] [%s.%s] [%v]", builder.desc, time.Since(builder.start), msg.MainType, msg.SubType, builder.rsp) log.Printf("rsp %s [%v] [%s.%s] [%v]", builder.Desc, time.Since(builder.start), msg.MainType, msg.SubType, builder.rsp)
} }
} }

View File

@ -10,16 +10,16 @@ import (
var user_builders = []*TestCase{ var user_builders = []*TestCase{
{ {
//create //create
desc: "创角", Desc: "创角",
mainType: string(comm.ModuleUser), mainType: string(comm.ModuleUser),
subType: user.UserSubTypeCreate, subType: user.UserSubTypeCreate,
req: &pb.UserCreateReq{ //设置请求参数 req: &pb.UserCreateReq{ //设置请求参数
NickName: "乐谷6301", NickName: "乐谷6301",
}, },
rsp: &pb.UserCreateRsp{}, rsp: &pb.UserCreateRsp{},
// enabled: true, // enabled: true,
}, { }, {
desc: "添加资源", Desc: "添加资源",
mainType: string(comm.ModuleUser), mainType: string(comm.ModuleUser),
subType: user.UserSubTypeAddRes, subType: user.UserSubTypeAddRes,
req: &pb.UserAddResReq{ //设置请求参数 req: &pb.UserAddResReq{ //设置请求参数
@ -27,7 +27,7 @@ var user_builders = []*TestCase{
Count: 100, Count: 100,
}, },
rsp: &pb.UserAddResResp{}, rsp: &pb.UserAddResResp{},
// enabled: true, enabled: true,
}, },
} }

View File

@ -12,7 +12,7 @@ func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.FriendListReq)
} }
//好友列表 //好友列表
func (this *apiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendListReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) List(session comm.IUserSession, req *pb.FriendListReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendListRsp rsp *pb.FriendListRsp

View File

@ -7,9 +7,9 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
func (this *apiComp) SearchCheck(session comm.IUserSession, req *pb.FriendSearchReq) (code comm.ErrorCode) { func (this *apiComp) SearchCheck(session comm.IUserSession, req *pb.FriendSearchReq) (code pb.ErrorCode) {
if req.NickName == "" { if req.NickName == "" {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSearchNameEmpty} code = pb.ErrorCode_FriendSearchNameEmpty
return return
} }
return return

View File

@ -165,6 +165,14 @@ func (this *ModelHero) mergeMainProperty(uid, heroId string, data map[string]int
hero.Property[comm.Hp] += data[comm.Hp] hero.Property[comm.Hp] += data[comm.Hp]
hero.Property[comm.Atk] += data[comm.Atk] hero.Property[comm.Atk] += data[comm.Atk]
hero.Property[comm.Def] += data[comm.Def] hero.Property[comm.Def] += data[comm.Def]
update := map[string]interface{}{
comm.Hp: hero.Property[comm.Hp],
comm.Atk: hero.Property[comm.Atk],
comm.Def: hero.Property[comm.Def],
}
if err := this.modifyHeroData(uid, heroId, update); err != nil {
log.Errorf("mergeMainProperty err %v", err)
}
} }
//合并附加属性 //合并附加属性
@ -173,9 +181,17 @@ func (this *ModelHero) mergeAddProperty(uid, heroId string, data map[string]int3
if hero == nil { if hero == nil {
return return
} }
hero.AddProperty[comm.Hp] = data[comm.Hp] hero.AddProperty[comm.HpPro] += data[comm.HpPro]
hero.AddProperty[comm.Atk] = data[comm.Atk] hero.AddProperty[comm.AtkPro] += data[comm.AtkPro]
hero.AddProperty[comm.Def] = data[comm.Def] hero.AddProperty[comm.DefPro] += data[comm.DefPro]
update := map[string]interface{}{
comm.HpPro: hero.AddProperty[comm.HpPro],
comm.AtkPro: hero.AddProperty[comm.AtkPro],
comm.DefPro: hero.AddProperty[comm.DefPro],
}
if err := this.modifyHeroData(uid, heroId, update); err != nil {
log.Errorf("mergeAddProperty err %v", err)
}
} }
//属性计算 - 暂时放在modelHero里实现 //属性计算 - 暂时放在modelHero里实现