工具优化
This commit is contained in:
parent
158ea726cf
commit
a6b30ad1f2
@ -32,5 +32,11 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.GourmetGetListRe
|
|||||||
|
|
||||||
// 任务统计
|
// 任务统计
|
||||||
this.module.ModuleRtask.SendToRtask(session, comm.Rtype136, _gourmet.TotalTime)
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype136, _gourmet.TotalTime)
|
||||||
|
resp := &pb.GourmetCreateOrderReq{}
|
||||||
|
resp.Order = append(resp.Order, &pb.OrderCook{
|
||||||
|
FoodType: 1001,
|
||||||
|
FoodCount: 10,
|
||||||
|
})
|
||||||
|
this.CreateOrder(session, resp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CrateMailReq struct {
|
type CrateMailReq struct {
|
||||||
Uid string // uid
|
Uid string `json:"uid"` // uid
|
||||||
Title string // 邮件标题
|
Title string `json:"title"` // 邮件标题
|
||||||
Contex string // 邮件内容 支持自定义
|
Contex string `json:"contex"` // 邮件内容 支持自定义
|
||||||
Items []*pb.UserAssets // 附件
|
Items []*pb.UserAssets // 附件
|
||||||
Cid string // 多语言表id
|
Cid string `json:"cid"` // 多语言表id
|
||||||
Param []string // 自定义参数
|
Param []string // 自定义参数
|
||||||
Sign string `json:"sign"`
|
Sign string `json:"sign"`
|
||||||
}
|
}
|
||||||
|
@ -364,3 +364,45 @@ func (r Robot) AddGrormetItem() bool {
|
|||||||
func (r *Robot) SetAccount(account string) {
|
func (r *Robot) SetAccount(account string) {
|
||||||
r.account = account
|
r.account = account
|
||||||
}
|
}
|
||||||
|
func (r Robot) GourmetOrder() int64 {
|
||||||
|
var byteLen int64
|
||||||
|
mainType := "gourmet"
|
||||||
|
subType := "createorder"
|
||||||
|
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||||
|
|
||||||
|
rsp := &pb.GourmetCreateOrderReq{}
|
||||||
|
rsp.Order = append(rsp.Order, &pb.OrderCook{
|
||||||
|
FoodType: 1001,
|
||||||
|
FoodCount: 10,
|
||||||
|
})
|
||||||
|
msg.Sec = r.BuildSecStr()
|
||||||
|
if comm.ProtoMarshal(rsp, msg) {
|
||||||
|
data, _ := proto.Marshal(msg)
|
||||||
|
err := r.ws.WriteMessage(websocket.BinaryMessage, data)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("WriteMessage err:%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
var msg *pb.UserMessage = &pb.UserMessage{}
|
||||||
|
_, data, err := r.ws.ReadMessage()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("readMessage err:%v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
|
fmt.Printf("unmarshal err:%v", err)
|
||||||
|
}
|
||||||
|
if msg.MainType == mainType && msg.SubType == subType {
|
||||||
|
byteLen += int64(len(data))
|
||||||
|
resp := &pb.GourmetCreateOrderResp{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return byteLen
|
||||||
|
}
|
||||||
|
@ -59,7 +59,7 @@ func Dispose(ctx context.Context, concurrency, totalNumber uint64, request *mode
|
|||||||
head := &pb.UserMessage{MainType: "user", SubType: "login"}
|
head := &pb.UserMessage{MainType: "user", SubType: "login"}
|
||||||
// 先登录
|
// 先登录
|
||||||
r.SendToClient(head, &pb.UserLoginReq{})
|
r.SendToClient(head, &pb.UserLoginReq{})
|
||||||
r.AddGrormetItem()
|
//r.AddGrormetItem()
|
||||||
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
|
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
|
||||||
case 2:
|
case 2:
|
||||||
// 并发建立长链接
|
// 并发建立长链接
|
||||||
|
@ -3,17 +3,12 @@ package golink
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go_dreamfactory/comm"
|
|
||||||
"go_dreamfactory/pb"
|
|
||||||
"go_dreamfactory/stress/helper"
|
"go_dreamfactory/stress/helper"
|
||||||
"go_dreamfactory/stress/model"
|
"go_dreamfactory/stress/model"
|
||||||
"go_dreamfactory/stress/robot"
|
"go_dreamfactory/stress/robot"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -87,29 +82,31 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
|
|||||||
//startTime := time.Now()
|
//startTime := time.Now()
|
||||||
// r.GetRandUser() // 获取随机在线玩家数据
|
// r.GetRandUser() // 获取随机在线玩家数据
|
||||||
|
|
||||||
r.GetGourmetList()
|
byteLen = r.GourmetOrder()
|
||||||
|
if byteLen > 0 {
|
||||||
for {
|
isSucceed = true
|
||||||
var msg *pb.UserMessage = &pb.UserMessage{}
|
|
||||||
data, err := r.GetMessagedata()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("readMessage err:%v", err)
|
|
||||||
isSucceed = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err = proto.Unmarshal(data, msg); err != nil {
|
|
||||||
fmt.Printf("unmarshal err:%v", err)
|
|
||||||
}
|
|
||||||
if msg.MainType == "gourmet" && msg.SubType == "getlist" {
|
|
||||||
byteLen += int64(len(data))
|
|
||||||
isSucceed = true
|
|
||||||
resp := &pb.GourmetGetListResp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
|
|
||||||
break
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// for {
|
||||||
|
// var msg *pb.UserMessage = &pb.UserMessage{}
|
||||||
|
// data, err := r.GetMessagedata()
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("readMessage err:%v", err)
|
||||||
|
// isSucceed = false
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
|
// fmt.Printf("unmarshal err:%v", err)
|
||||||
|
// }
|
||||||
|
// if msg.MainType == "gourmet" && msg.SubType == "getlist" {
|
||||||
|
// byteLen += int64(len(data))
|
||||||
|
// isSucceed = true
|
||||||
|
// resp := &pb.GourmetGetListResp{}
|
||||||
|
// if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
requestTime := uint64(helper.DiffNano(startTime))
|
requestTime := uint64(helper.DiffNano(startTime))
|
||||||
requestResults := &model.RequestResults{
|
requestResults := &model.RequestResults{
|
||||||
|
Loading…
Reference in New Issue
Block a user