Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: hanzhixiao <709674996@qq.com>
  • Loading branch information
hanzhixiao committed Aug 1, 2023
1 parent a7ac966 commit 1bbd49c
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 18 deletions.
3 changes: 0 additions & 3 deletions start.bat

This file was deleted.

1 change: 0 additions & 1 deletion build.cmd → testv3new/build.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cd ./testv3new
go test -c pressure_test.go pressure_tester.go register_manager.go test_struct.go -o pressure_test.exe
5 changes: 5 additions & 0 deletions testv3new/constant/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constant

const (
DefaultGroupMember = "register_test_1"
)
37 changes: 33 additions & 4 deletions testv3new/pressure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testv3new
import (
"fmt"
"github.com/OpenIMSDK/tools/log"
"open_im_sdk/testv3new/constant"
"open_im_sdk/testv3new/testcore"
"testing"
"time"
Expand All @@ -22,20 +23,36 @@ func init() {

func TestPressureTester_PressureSendMsgs(t *testing.T) {
ParseFlag()
var sendUserIDs []string
var recvUserIDs []string
for i := 0; i < pressureTestAttribute.sendNums; i++ {
sendUserIDs = append(sendUserIDs, fmt.Sprintf("register_test_%v", i))
}
for i := 0; i < pressureTestAttribute.recvNums; i++ {
recvUserIDs = append(recvUserIDs, fmt.Sprintf("register_test_%v", i+pressureTestAttribute.sendNums))
}
p := NewPressureTester(testcore.APIADDR, testcore.WSADDR)
for i := 0; i < 10; i++ {
p.WithTimer(p.PressureSendMsgs2)(pressureTestAttribute.sendUserIDs, pressureTestAttribute.recvUserIDs, pressureTestAttribute.messageNumber, time.Duration(pressureTestAttribute.timeInterval)*time.Millisecond)
time.Sleep(time.Second)
p.WithTimer(p.PressureSendMsgs2)(sendUserIDs, recvUserIDs, pressureTestAttribute.messageNumber, time.Duration(pressureTestAttribute.timeInterval)*time.Millisecond)
time.Sleep(time.Duration(pressureTestAttribute.timeInterval) * time.Second)
}
// time.Sleep(1000 * time.Second)
}

func TestPressureTester_PressureSendGroupMsgs(t *testing.T) {
ParseFlag()
var sendUserIDs []string
var groupIDs []string
for i := 0; i < pressureTestAttribute.sendNums; i++ {
sendUserIDs = append(sendUserIDs, fmt.Sprintf("register_test_%v", i))
}
for i := 0; i < pressureTestAttribute.groupNums; i++ {
sendUserIDs = append(sendUserIDs, fmt.Sprintf("group_test_%v", i))
}
p := NewPressureTester(testcore.APIADDR, testcore.WSADDR)
for i := 0; i < 10; i++ {
p.WithTimer(p.PressureSendGroupMsgs2)(pressureTestAttribute.sendUserIDs, pressureTestAttribute.groupIDs, pressureTestAttribute.messageNumber, time.Duration(pressureTestAttribute.timeInterval)*time.Millisecond)
time.Sleep(time.Second)
p.WithTimer(p.PressureSendGroupMsgs2)(sendUserIDs, groupIDs, pressureTestAttribute.messageNumber, time.Duration(pressureTestAttribute.timeInterval)*time.Millisecond)
time.Sleep(time.Duration(pressureTestAttribute.timeInterval) * time.Second)
}
}

Expand Down Expand Up @@ -64,3 +81,15 @@ func TestPressureTester_PressureSendMsgs2(t *testing.T) {
time.Sleep(time.Second)
}
}

func Test_CreateGroup(t *testing.T) {
count := 1000
ownerUserID := "register_test_0"
for i := 0; i < count; i++ {
p := NewPressureTester(testcore.APIADDR, testcore.WSADDR)
err := p.CreateGroup(fmt.Sprintf("group_test_%v", i), ownerUserID, []string{constant.DefaultGroupMember}, fmt.Sprintf("group_test_%v", i))
if err != nil {
t.Fatal(err)
}
}
}
1 change: 1 addition & 0 deletions testv3new/pressure_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (p *PressureTester) add(a, b int) int {

func (p *PressureTester) initCores(m *map[string]*testcore.BaseCore, userIDs []string) {
for _, userID := range userIDs {

token, err := p.registerManager.GetToken(userID)
if err != nil {
log.ZError(context.Background(), "get token error", err, "userID", userID)
Expand Down
25 changes: 23 additions & 2 deletions testv3new/register_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ func (r *RegisterManager) GetToken(userID string) (string, error) {
}

func (p *PressureTester) CreateGroup(groupID string, ownerUserID string, userIDs []string, groupName string) error {
ctx, _ := InitContext(ownerUserID)
token, err := p.registerManager.GetToken(ownerUserID)
if err != nil {
log.ZError(context.Background(), "get token error", err, "userID", ownerUserID)
return err
}
ctx, _ := InitContextWithToken(ownerUserID, token)
req := &group.CreateGroupReq{
MemberUserIDs: userIDs,
AdminUserIDs: []string{},
Expand All @@ -118,7 +123,7 @@ func (p *PressureTester) CreateGroup(groupID string, ownerUserID string, userIDs
},
}
resp := &group.CreateGroupResp{}
err := util.ApiPost(ctx, constant.CreateGroupRouter, &req, &resp)
err = util.ApiPost(ctx, constant.CreateGroupRouter, &req, &resp)
if err != nil {
log.ZError(ctx, "ApiPost failed ", err, "addr", testcore.TOKENADDR, "req", req)
return err
Expand Down Expand Up @@ -177,3 +182,19 @@ func InitContext(uid string) (context.Context, *ccontext.GlobalConfig) {
ctx = ccontext.WithOperationID(ctx, utils.OperationIDGenerator())
return ctx, &config
}

func InitContextWithToken(uid string, token string) (context.Context, *ccontext.GlobalConfig) {
config := ccontext.GlobalConfig{
UserID: uid, Token: token,
IMConfig: sdk_struct.IMConfig{
PlatformID: constant.AndroidPlatformID,
ApiAddr: testcore.APIADDR,
WsAddr: testcore.WSADDR,
LogLevel: 2,
IsLogStandardOutput: true,
LogFilePath: "./",
}}
ctx := ccontext.WithInfo(context.Background(), &config)
ctx = ccontext.WithOperationID(ctx, utils.OperationIDGenerator())
return ctx, &config
}
3 changes: 3 additions & 0 deletions testv3new/start.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd /d %~dp0
start ./pressure_test.exe --test.run TestPressureTester_PressureSendMsgs -m 1 -t 1 -s 1000 -r 1 -g 0
start ./pressure_test.exe --test.run TestPressureTester_PressureSendGroupMsgs -m 1 -t 1 -s 1000 -r 0 -g 1000
12 changes: 6 additions & 6 deletions testv3new/test_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ func (s *sliceValue) Set(val string) error {

type PressureTestAttribute struct {
messageNumber int
sendUserIDs sliceValue
recvUserIDs sliceValue
groupIDs sliceValue
sendNums int
recvNums int
groupNums int
timeInterval int64
}

func (r *PressureTestAttribute) InitWithFlag() {
flag.IntVar(&r.messageNumber, "m", 0, "messageNumber for single sender")
flag.Var(&r.sendUserIDs, "s", "sender id list")
flag.Var(&r.recvUserIDs, "r", "recv id list")
flag.Var(&r.groupIDs, "g", "groupID for testing")
flag.IntVar(&r.sendNums, "s", 0, "the number of senders for testing")
flag.IntVar(&r.recvNums, "r", 0, "the number of receivers for testing")
flag.IntVar(&r.groupNums, "g", 0, "group for testing")
flag.Int64Var(&r.timeInterval, "t", 0, "timeInterVal during sending message")
}

Expand Down
4 changes: 2 additions & 2 deletions testv3new/testcore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

// system
var (
TESTIP = "203.56.175.233"
TESTIP = "43.128.72.19"
APIADDR = fmt.Sprintf("http://%v:10002", TESTIP)
WSADDR = fmt.Sprintf("ws://%v:10001", TESTIP)
SECRET = "tuoyun"
SECRET = "openIM123"

REGISTERADDR = APIADDR + constant.UserRegister
TOKENADDR = APIADDR + constant.GetUsersToken
Expand Down

0 comments on commit 1bbd49c

Please sign in to comment.