消息长度,错误信息统计
This commit is contained in:
parent
58bcc8c15d
commit
b61ecc23e3
@ -168,15 +168,15 @@ func (r *RobotFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|||||||
return b.Bytes(), nil
|
return b.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Robot) MessageRsp(mainType, subType string) bool {
|
func (r *Robot) MessageRsp(mainType, subType string) (bool, int64) {
|
||||||
|
var byteLen int64
|
||||||
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 {
|
||||||
fmt.Printf("readMessage err:%v", err)
|
fmt.Printf("readMessage err:%v", err)
|
||||||
return false
|
return false, byteLen
|
||||||
}
|
}
|
||||||
|
byteLen = int64(len(data))
|
||||||
if err = proto.Unmarshal(data, msg); err != nil {
|
if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
fmt.Printf("unmarshal err:%v", err)
|
fmt.Printf("unmarshal err:%v", err)
|
||||||
}
|
}
|
||||||
@ -184,19 +184,19 @@ func (r *Robot) MessageRsp(mainType, subType string) bool {
|
|||||||
if msg.MainType == "chat" && msg.SubType == "message" {
|
if msg.MainType == "chat" && msg.SubType == "message" {
|
||||||
resp := &pb.ChatMessagePush{}
|
resp := &pb.ChatMessagePush{}
|
||||||
if !comm.ProtoUnmarshal(msg, resp) {
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
return false
|
return false, byteLen
|
||||||
}
|
}
|
||||||
return false
|
return false, byteLen
|
||||||
//fmt.Printf("接收消息=====resp:%v\n", resp.Chat)
|
//fmt.Printf("接收消息=====resp:%v\n", resp.Chat)
|
||||||
} else if msg.MainType == mainType && msg.SubType == subType {
|
} else if msg.MainType == mainType && msg.SubType == subType {
|
||||||
resp := &pb.UserLoginResp{}
|
resp := &pb.UserLoginResp{}
|
||||||
if !comm.ProtoUnmarshal(msg, resp) {
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
return false
|
return false, byteLen
|
||||||
}
|
}
|
||||||
//fmt.Printf("接收消息=====loginData:%v,userExpand:%v\n", resp.Data, resp.Ex)
|
//fmt.Printf("接收消息=====loginData:%v,userExpand:%v\n", resp.Data, resp.Ex)
|
||||||
return true
|
return true, byteLen
|
||||||
}
|
}
|
||||||
return false
|
return false, byteLen
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Robot) CloseHandler() {
|
func (r *Robot) CloseHandler() {
|
||||||
@ -212,3 +212,42 @@ func (r *Robot) GetMessagedata() []byte {
|
|||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
func (r *Robot) Login() error {
|
||||||
|
msg := &pb.UserMessage{MainType: "user", SubType: "login"}
|
||||||
|
rsp := &pb.UserLoginReq{
|
||||||
|
Account: "user001",
|
||||||
|
Sid: "dfmxf",
|
||||||
|
}
|
||||||
|
msg.Sec = r.BuildSecStr()
|
||||||
|
if comm.ProtoMarshal(rsp, msg) {
|
||||||
|
data, _ := proto.Marshal(msg)
|
||||||
|
return r.ws.WriteMessage(websocket.BinaryMessage, data)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) Create() bool {
|
||||||
|
mainType := "user"
|
||||||
|
subType := "create"
|
||||||
|
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||||
|
rsp := &pb.UserCreateReq{
|
||||||
|
NickName: "001",
|
||||||
|
Figure: 100,
|
||||||
|
Gender: 0,
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
if b, _ := r.MessageRsp(mainType, subType); b {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ func init() {
|
|||||||
|
|
||||||
// webSocket
|
// webSocket
|
||||||
model.RegisterVerifyWebSocket("json", verify.WebSocketJSON)
|
model.RegisterVerifyWebSocket("json", verify.WebSocketJSON)
|
||||||
|
model.RegisterVerifyWebSocket("pb", verify.WebSocketProto)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispose 处理函数
|
// Dispose 处理函数
|
||||||
@ -52,13 +53,6 @@ func Dispose(ctx context.Context, concurrency, totalNumber uint64, request *mode
|
|||||||
case 1:
|
case 1:
|
||||||
// 连接以后再启动协程
|
// 连接以后再启动协程
|
||||||
r := robot.NewRobot(request.URL)
|
r := robot.NewRobot(request.URL)
|
||||||
// head := &pb.UserMessage{MainType: "user", SubType: "login"}
|
|
||||||
// req := &pb.UserLoginReq{
|
|
||||||
// Account: "user001",
|
|
||||||
// Sid: "dfmxf",
|
|
||||||
// }
|
|
||||||
// r.SendToClient(head, req)
|
|
||||||
// r.MessageRsp()
|
|
||||||
|
|
||||||
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
|
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -72,6 +72,7 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
|
|||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
isSucceed = false
|
isSucceed = false
|
||||||
errCode = model.HTTPOk
|
errCode = model.HTTPOk
|
||||||
|
byteLen int64 // 协议传输字节数
|
||||||
)
|
)
|
||||||
// 需要发送的数据
|
// 需要发送的数据
|
||||||
head := &pb.UserMessage{MainType: "user", SubType: "login"}
|
head := &pb.UserMessage{MainType: "user", SubType: "login"}
|
||||||
@ -81,18 +82,23 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
|
|||||||
}
|
}
|
||||||
r.SendToClient(head, req)
|
r.SendToClient(head, req)
|
||||||
for {
|
for {
|
||||||
if r.MessageRsp("user", "login") {
|
|
||||||
|
if b, len := r.MessageRsp("user", "login"); b {
|
||||||
|
byteLen += len
|
||||||
isSucceed = true
|
isSucceed = true
|
||||||
errCode, isSucceed = request.GetVerifyWebSocket()(request, "webSocket.json", r.GetMessagedata())
|
//errCode, isSucceed = request.GetVerifyWebSocket()(request, "webSocket.pb", r.GetMessagedata())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
requestTime := uint64(helper.DiffNano(startTime))
|
requestTime := uint64(helper.DiffNano(startTime))
|
||||||
requestResults := &model.RequestResults{
|
requestResults := &model.RequestResults{
|
||||||
Time: requestTime,
|
ID: "",
|
||||||
IsSucceed: isSucceed,
|
ChanID: chanID,
|
||||||
ErrCode: errCode,
|
Time: requestTime,
|
||||||
|
IsSucceed: isSucceed,
|
||||||
|
ErrCode: errCode,
|
||||||
|
ReceivedBytes: byteLen,
|
||||||
}
|
}
|
||||||
requestResults.SetID(chanID, i)
|
requestResults.SetID(chanID, i)
|
||||||
ch <- requestResults
|
ch <- requestResults
|
||||||
|
@ -38,7 +38,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
|
|||||||
maxTime uint64 // 最大时长
|
maxTime uint64 // 最大时长
|
||||||
minTime uint64 // 最小时长
|
minTime uint64 // 最小时长
|
||||||
successNum uint64 // 成功处理数,code为0
|
successNum uint64 // 成功处理数,code为0
|
||||||
failureNum uint64 // 处理失败数,code不为0
|
failureNum uint64 // 处理失败数,code不为0 0
|
||||||
chanIDLen int // 并发数
|
chanIDLen int // 并发数
|
||||||
chanIDs = make(map[uint64]bool)
|
chanIDs = make(map[uint64]bool)
|
||||||
receivedBytes int64
|
receivedBytes int64
|
||||||
|
@ -4,8 +4,11 @@ package verify
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/stress/model"
|
"go_dreamfactory/stress/model"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WebSocketResponseJSON 返回数据结构体,返回值为json
|
// WebSocketResponseJSON 返回数据结构体,返回值为json
|
||||||
@ -47,3 +50,29 @@ func WebSocketJSON(request *model.Request, seq string, msg []byte) (code int, is
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WebSocketProto(request *model.Request, seq string, data []byte) (code int, isSucceed bool) {
|
||||||
|
|
||||||
|
var msg *pb.UserMessage = &pb.UserMessage{}
|
||||||
|
|
||||||
|
if err := proto.Unmarshal(data, msg); err != nil {
|
||||||
|
fmt.Printf("unmarshal err:%v", err)
|
||||||
|
}
|
||||||
|
//fmt.Printf("接收消息=====msg.MainType = %s,msg.SubType = %s\n", msg.MainType, msg.SubType)
|
||||||
|
if msg.MainType == "chat" && msg.SubType == "message" {
|
||||||
|
resp := &pb.ChatMessagePush{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
|
code = model.ParseError
|
||||||
|
}
|
||||||
|
return
|
||||||
|
//fmt.Printf("接收消息=====resp:%v\n", resp.Chat)
|
||||||
|
} else if msg.MainType == "user" && msg.SubType == "login" {
|
||||||
|
resp := &pb.UserLoginResp{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
|
code = model.ParseError
|
||||||
|
}
|
||||||
|
//fmt.Printf("接收消息=====loginData:%v,userExpand:%v\n", resp.Data, resp.Ex)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -74,6 +74,7 @@ func main() {
|
|||||||
totalNumber = 10
|
totalNumber = 10
|
||||||
debugStr = "false"
|
debugStr = "false"
|
||||||
requestURL = "ws://10.0.0.9:7891/gateway"
|
requestURL = "ws://10.0.0.9:7891/gateway"
|
||||||
|
verify = "pb"
|
||||||
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
|
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
|
||||||
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")
|
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")
|
||||||
fmt.Printf("压测地址或curl路径必填 \n")
|
fmt.Printf("压测地址或curl路径必填 \n")
|
||||||
|
Loading…
Reference in New Issue
Block a user