Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test function about user register #93

Merged
merged 5 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion testv2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func GetUserToken(ctx context.Context, userID string) (string, error) {
jsonReqData, err := json.Marshal(map[string]any{
"userID": userID,
"platformID": 1,
//"secret": "openIM123",
"secret": "openIM123",
//"secret": "111111",
})
if err != nil {
Expand Down Expand Up @@ -212,6 +212,11 @@ type onAdvancedMsgListener struct {
ctx context.Context
}

func (o *onAdvancedMsgListener) OnRecvOfflineNewMessage(message string) {
//TODO implement me
panic("implement me")
}

func (o *onAdvancedMsgListener) OnMsgDeleted(message string) {
log.ZInfo(o.ctx, "OnMsgDeleted", "message", message)
}
Expand Down
27 changes: 18 additions & 9 deletions testv3/funcation/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import (
"time"
)

func register(uid string) error {
initContext(uid)
//ACCOUNTCHECK
func Register(uid, nickname, faceurl string) (bool, error) {
InitContext(uid)
err := checkUserAccount(uid)
return registerUserAccount(uid, nickname, faceurl), err
}

func checkUserAccount(uid string) error {
var getAccountCheckReq userPB.AccountCheckReq
var getAccountCheckResp userPB.AccountCheckResp
getAccountCheckReq.CheckUserIDs = []string{uid}
Expand All @@ -33,21 +37,26 @@ func register(uid string) error {
continue
}
}
return nil
}

var rreq userPB.UserRegisterReq
rreq.Users = []*sdkws.UserInfo{{UserID: uid}}
func registerUserAccount(uid, nickname, faceurl string) bool {
var req userPB.UserRegisterReq
req.Users = []*sdkws.UserInfo{{UserID: uid, Nickname: nickname, FaceURL: faceurl}}
req.Secret = Secret
for {
err := util.ApiPost(ctx, "/auth/user_register", &rreq, nil)
err := util.ApiPost(ctx, "/user/user_register", &req, nil)
if err != nil {
log.Error("post failed ,continue ", err.Error(), REGISTERADDR, getAccountCheckReq.CheckUserIDs)
log.Error("post failed ,continue ", err.Error(), REGISTERADDR)
time.Sleep(100 * time.Millisecond)
continue
} else {
log.Info("register ok ", REGISTERADDR, getAccountCheckReq.CheckUserIDs)
log.Info("register ok ", REGISTERADDR)
userLock.Lock()
allUserID = append(allUserID, uid)
userLock.Unlock()
return nil
return true
}
}
return false
}
8 changes: 7 additions & 1 deletion testv3/funcation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
var (
rotateCount = uint(0)
LogLevel = uint32(6)
PlatformID = int32(2)
PlatformID = int32(1)
Secret = "tuoyun"
IsLogStandardOutput = true
isLogJson = false
LogName = ""
Expand Down Expand Up @@ -78,3 +79,8 @@ var MaxNumGoroutine = 100000

// var Msgwg sync.WaitGroup
var sendMsgClient = 0

// Listener
var (
testConversation conversationCallBack
)
32 changes: 23 additions & 9 deletions testv3/funcation/friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func ReliabilityInitAndLogin(index int, uid, token string) {
allLoginMgr[index].mgr = lg
log.Info(uid, "InitSDK ", cf, "index mgr", index, lg)

var testConversation conversationCallBack
lg.SetConversationListener(&testConversation)

var testUser userCallback
Expand Down Expand Up @@ -139,12 +138,35 @@ type conversationCallBack struct {
SyncFlag int
}

func (c *conversationCallBack) OnError(errCode int32, errMsg string) {
//TODO implement me
panic("implement me")
}

func (c *conversationCallBack) OnSuccess(data string) {
//TODO implement me
panic("implement me")
}

func (c *conversationCallBack) OnNewConversation(conversationList string) {
log.Info("", "OnNewConversation returnList is ", conversationList)
}

func (c *conversationCallBack) OnConversationChanged(conversationList string) {
log.Info("", "OnConversationChanged returnList is", conversationList)
}

type userCallback struct {
}

type MsgListenerCallBak struct {
}

func (m *MsgListenerCallBak) OnRecvOfflineNewMessage(message string) {
//TODO implement me
panic("implement me")
}

func (m *MsgListenerCallBak) OnRecvNewMessage(message string) {
//TODO implement me
panic("implement me")
Expand Down Expand Up @@ -312,14 +334,6 @@ func (c *conversationCallBack) OnSyncServerFailed() {
log.Info("", utils.GetSelfFuncName())
}

func (c *conversationCallBack) OnNewConversation(conversationList string) {
log.Info("", "OnNewConversation returnList is ", conversationList)
}

func (c *conversationCallBack) OnConversationChanged(conversationList string) {
log.Info("", "OnConversationChanged returnList is", conversationList)
}

func (c *conversationCallBack) OnTotalUnreadMessageCountChanged(totalUnreadCount int32) {
log.Info("", "OnTotalUnreadMessageCountChanged returnTotalUnreadCount is ", totalUnreadCount)
}
84 changes: 83 additions & 1 deletion testv3/funcation/reliability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package funcation

import (
"math/rand"
"open_im_sdk/open_im_sdk"
"open_im_sdk/pkg/log"
"open_im_sdk/pkg/sdk_params_callback"
"open_im_sdk/pkg/utils"
"os"
"runtime"
Expand All @@ -13,7 +15,7 @@ import (

func RegisterReliabilityUser(id int, timeStamp string) {
userID := GenUid(id, "reliability_"+timeStamp)
register(userID)
//Register(userID)
token, _ := RunGetToken(userID)
coreMgrLock.Lock()
defer coreMgrLock.Unlock()
Expand Down Expand Up @@ -60,6 +62,17 @@ func ReliabilityTest(msgNumOneClient int, intervalSleepMS int, randSleepMaxSecon
wg.Wait()
log.Warn("send msg finish, CheckReliabilityResult")
time.Sleep(time.Duration(3000) * time.Second)

// 所有成员拉取自己的会话是否有更新
for i := 0; i < clientNum; i++ {
var params sdk_params_callback.GetAdvancedHistoryMessageListParams
params.UserID = allLoginMgr[i].userID
//params.ConversationID = "si_7788_7789"
//params.StartClientMsgID = "83ca933d559d0374258550dd656a661c"
params.Count = 20
open_im_sdk.GetAdvancedHistoryMessageList(&testConversation, utils.OperationIDGenerator(), utils.StructToJsonString(params))
}

//for {
// // 消息异步落库可能出现延迟,每隔五秒再检查一次
// if CheckReliabilityResult(msgNumOneClient, clientNum) {
Expand Down Expand Up @@ -118,3 +131,72 @@ func ReliabilityOne(index int, beforeLoginSleep int, isSendMsg bool, intervalSle
//Msgwg.Done()
}
}

func CheckReliabilityResult(msgNumOneClient int, clientNum int) bool {
log.Info("", "start check map send -> map recv")
sameNum := 0

// 消息数量不一致说明出现丢失
if len(SendSuccAllMsg)+len(SendFailedAllMsg) != msgNumOneClient*clientNum {
log.Warn("", utils.GetSelfFuncName(), " send msg success number: ", len(SendSuccAllMsg),
" send msg failed number: ", len(SendFailedAllMsg), " all: ", msgNumOneClient*clientNum)
return false
}

for ksend, _ := range SendSuccAllMsg {
_, ok := RecvAllMsg[ksend] // RecvAllMsg 的初始化何时?
if ok {
sameNum++
} else {
// 埋点日志,第 ksend 个消息数据 本地和服务器不一致
log.Error("", "check failed not in recv ", ksend)
log.Error("", "send failed num: ", len(SendFailedAllMsg),
" send success num: ", len(SendSuccAllMsg), " recv num: ", len(RecvAllMsg))
return false
}
}
log.Info("", "check map send -> map recv ok ", sameNum)
//log.Info("", "start check map recv -> map send ")
//sameNum = 0

//for k1, _ := range RecvAllMsg {
// _, ok := SendSuccAllMsg[k1]
// if ok {
// sameNum++
// //x := v1 + v2
// //x = x + x
//
// } else {
// log.Error("", "check failed not in send ", k1, len(SendFailedAllMsg), len(SendSuccAllMsg), len(RecvAllMsg))
// // return false
// }
//}
maxCostMsgID := ""
minCostTime := int64(1000000)
maxCostTime := int64(0)
totalCostTime := int64(0)
for ksend, vsend := range SendSuccAllMsg {
krecv, ok := RecvAllMsg[ksend]
if ok {
sameNum++
costTime := krecv.RecvTime - vsend.SendTime
totalCostTime += costTime
if costTime > maxCostTime {
maxCostMsgID = ksend
maxCostTime = costTime
}
if minCostTime > costTime {
minCostTime = costTime
}
}
}

log.Warn("", "need send msg num : ", sendMsgClient*msgNumInOneClient)
log.Warn("", "send msg succ num ", len(SendSuccAllMsg))
log.Warn("", "send msg failed num ", len(SendFailedAllMsg))
log.Warn("", "recv msg succ num ", len(RecvAllMsg))
log.Warn("", "minCostTime: ", minCostTime, "ms, maxCostTime: ", maxCostTime, "ms, average cost time: ",
totalCostTime/(int64(sendMsgClient*msgNumInOneClient)), "ms", " maxCostMsgID: ", maxCostMsgID)

return true
}
2 changes: 2 additions & 0 deletions testv3/funcation/sendMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type SendRecvTime struct {
}

var SendSuccAllMsg map[string]*SendRecvTime //msgid->send+recv:
var SendFailedAllMsg map[string]string
var RecvAllMsg map[string]*SendRecvTime //msgid->send+recv

func DoTestSendMsg(index int, sendId, recvID string, groupID string, idx string) {
m := "test msg " + sendId + ":" + recvID + ":" + idx
Expand Down
7 changes: 4 additions & 3 deletions testv3/funcation/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func getMyIP() string {
}

func getToken(uid string) (string, int64) {
initContext(uid)
InitContext(uid)
config.Token = ""
req := authPB.UserTokenReq{PlatformID: PlatformID, UserID: uid}
req := authPB.UserTokenReq{PlatformID: PlatformID, UserID: uid, Secret: Secret}
resp := authPB.UserTokenResp{}
err := util.ApiPost(ctx, "/auth/user_token", &req, &resp)
if err != nil {
Expand All @@ -70,7 +70,7 @@ func RunGetToken(strMyUid string) (string, int64) {
return token, exprie
}

func initContext(uid string) {
func InitContext(uid string) context.Context {
config = ccontext.GlobalConfig{
UserID: uid,
Token: AdminToken,
Expand All @@ -83,4 +83,5 @@ func initContext(uid string) {
}
ctx = ccontext.WithInfo(context.Background(), &config)
ctx = ccontext.WithOperationID(ctx, utils.OperationIDGenerator())
return ctx
}
46 changes: 0 additions & 46 deletions testv3/json_test.go

This file was deleted.

1 change: 0 additions & 1 deletion testv3/msg_delay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ func Test_Delay(t *testing.T) {
" single sender msg num: ", *singleSenderMsgNum, " send msg total num: ", *senderNum**singleSenderMsgNum)

funcation.ReliabilityTest(*singleSenderMsgNum, *intervalTime, 10, *senderNum)

}
17 changes: 17 additions & 0 deletions testv3/register_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testv3

import (
"open_im_sdk/testv3/funcation"
"testing"
)

func Test_Register(t *testing.T) {
uid := "123456"
nickname := "bantanger"
faceurl := ""
register, err := funcation.Register(uid, nickname, faceurl)
if err != nil {
t.Fatal(err)
}
t.Log(register)
}