-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: pressure test and msg test * new feat: modify dictory * feat: modify dictory
- Loading branch information
1 parent
9905403
commit 4adbb00
Showing
16 changed files
with
283 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package msgtest | ||
|
||
import "testing" | ||
|
||
func Test_CreateConversations(t *testing.T) { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package module | ||
|
||
import ( | ||
"fmt" | ||
"open_im_sdk/pkg/constant" | ||
"open_im_sdk/sdk_struct" | ||
"open_im_sdk/ws_wrapper/utils" | ||
|
||
"github.com/OpenIMSDK/protocol/msg" | ||
"github.com/OpenIMSDK/protocol/sdkws" | ||
) | ||
|
||
type ApiMsgSender struct { | ||
*MetaManager | ||
} | ||
|
||
type SendMsgReq struct { | ||
RecvID string `json:"recvID" binding:"required_if" message:"recvID is required if sessionType is SingleChatType or NotificationChatType"` | ||
SendMsg | ||
} | ||
|
||
type SendMsg struct { | ||
SendID string `json:"sendID" binding:"required"` | ||
GroupID string `json:"groupID" binding:"required_if=SessionType 2|required_if=SessionType 3"` | ||
SenderNickname string `json:"senderNickname"` | ||
SenderFaceURL string `json:"senderFaceURL"` | ||
SenderPlatformID int32 `json:"senderPlatformID"` | ||
Content map[string]interface{} `json:"content" binding:"required" swaggerignore:"true"` | ||
ContentType int32 `json:"contentType" binding:"required"` | ||
SessionType int32 `json:"sessionType" binding:"required"` | ||
IsOnlineOnly bool `json:"isOnlineOnly"` | ||
NotOfflinePush bool `json:"notOfflinePush"` | ||
OfflinePushInfo *sdkws.OfflinePushInfo `json:"offlinePushInfo"` | ||
} | ||
|
||
func (a *ApiMsgSender) SendMsg(sendID, recvID string, index int) error { | ||
content := fmt.Sprintf("this is test msg user %s to user %s, index: %d", sendID, recvID, index) | ||
text := sdk_struct.TextElem{Content: content} | ||
req := &SendMsgReq{ | ||
RecvID: recvID, | ||
SendMsg: SendMsg{ | ||
SendID: sendID, | ||
SenderPlatformID: constant.WindowsPlatformID, | ||
ContentType: constant.Text, | ||
SessionType: constant.SingleChatType, | ||
Content: map[string]interface{}{"content": utils.StructToJsonString(text)}, | ||
}, | ||
} | ||
var resp msg.SendMsgResp | ||
return a.postWithCtx(constant.SendMsgRouter, req, &resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package module | ||
|
||
import ( | ||
"open_im_sdk/pkg/constant" | ||
|
||
"github.com/OpenIMSDK/protocol/friend" | ||
) | ||
|
||
type TestFriendManager struct { | ||
*MetaManager | ||
} | ||
|
||
func (t *TestFriendManager) ImportFriends(ownerUserID string, friendUserIDs []string) error { | ||
req := &friend.ImportFriendReq{ | ||
OwnerUserID: ownerUserID, | ||
FriendUserIDs: friendUserIDs, | ||
} | ||
return t.postWithCtx(constant.ImportFriendListRouter, &req, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package module | ||
|
||
import ( | ||
"context" | ||
"open_im_sdk/pkg/constant" | ||
|
||
"github.com/OpenIMSDK/protocol/group" | ||
"github.com/OpenIMSDK/protocol/sdkws" | ||
) | ||
|
||
type TestGroupManager struct { | ||
*MetaManager | ||
} | ||
|
||
func (t *TestGroupManager) CreateGroup(groupID string, groupName string, ownerUserID string, userIDs []string) error { | ||
req := &group.CreateGroupReq{ | ||
MemberUserIDs: userIDs, | ||
OwnerUserID: ownerUserID, | ||
GroupInfo: &sdkws.GroupInfo{ | ||
GroupID: groupID, | ||
GroupName: groupName, | ||
GroupType: constant.WorkingGroup, | ||
CreatorUserID: ownerUserID, | ||
}, | ||
} | ||
resp := &group.CreateGroupResp{} | ||
return t.postWithCtx(constant.CreateGroupRouter, &req, &resp) | ||
} | ||
|
||
func (t *TestGroupManager) InviteUserToGroup(ctx context.Context, groupID string, invitedUserIDs []string) error { | ||
req := &group.InviteUserToGroupReq{ | ||
GroupID: groupID, | ||
InvitedUserIDs: invitedUserIDs, | ||
} | ||
resp := &group.InviteUserToGroupResp{} | ||
return t.postWithCtx(constant.InviteUserToGroupRouter, &req, &resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package module | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"open_im_sdk/internal/util" | ||
"open_im_sdk/pkg/constant" | ||
"open_im_sdk/pkg/sdkerrs" | ||
"open_im_sdk/pkg/utils" | ||
|
||
authPB "github.com/OpenIMSDK/protocol/auth" | ||
"github.com/OpenIMSDK/tools/log" | ||
"github.com/OpenIMSDK/tools/mcontext" | ||
) | ||
|
||
const ( | ||
ManagerUserID = "openIMAdmin" | ||
) | ||
|
||
type MetaManager struct { | ||
managerUserID string | ||
apiAddr string | ||
secret string | ||
token string | ||
} | ||
|
||
func NewMetaManager(apiAddr, secret, managerUserID string) *MetaManager { | ||
return &MetaManager{ | ||
managerUserID: managerUserID, | ||
apiAddr: apiAddr, | ||
secret: secret, | ||
} | ||
} | ||
|
||
func (m *MetaManager) NewUserManager() *TestUserManager { | ||
return &TestUserManager{m} | ||
} | ||
|
||
func (m *MetaManager) NewGroupMananger() *TestGroupManager { | ||
return &TestGroupManager{m} | ||
} | ||
|
||
func (m *MetaManager) NewFriendManager() *TestFriendManager { | ||
return &TestFriendManager{m} | ||
} | ||
|
||
func (m *MetaManager) NewApiMsgSender() *ApiMsgSender { | ||
return &ApiMsgSender{m} | ||
} | ||
|
||
func (m *MetaManager) apiPost(ctx context.Context, route string, req, resp any) (err error) { | ||
operationID, _ := ctx.Value("operationID").(string) | ||
if operationID == "" { | ||
err := sdkerrs.ErrArgs.Wrap("call api operationID is empty") | ||
return err | ||
} | ||
reqBody, err := json.Marshal(req) | ||
if err != nil { | ||
return sdkerrs.ErrSdkInternal.Wrap("json.Marshal(req) failed " + err.Error()) | ||
} | ||
reqUrl := m.apiAddr + route | ||
request, err := http.NewRequestWithContext(ctx, http.MethodPost, reqUrl, bytes.NewReader(reqBody)) | ||
if err != nil { | ||
return sdkerrs.ErrSdkInternal.Wrap("sdk http.NewRequestWithContext failed " + err.Error()) | ||
} | ||
log.ZDebug(ctx, "ApiRequest", "url", reqUrl, "body", string(reqBody)) | ||
request.ContentLength = int64(len(reqBody)) | ||
request.Header.Set("Content-Type", "application/json") | ||
request.Header.Set("operationID", operationID) | ||
if m.token != "" { | ||
request.Header.Set("token", m.token) | ||
} | ||
response, err := new(http.Client).Do(request) | ||
if err != nil { | ||
return sdkerrs.ErrNetwork.Wrap("ApiPost http.Client.Do failed " + err.Error()) | ||
} | ||
defer response.Body.Close() | ||
respBody, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
log.ZError(ctx, "ApiResponse", err, "type", "read body", "status", response.Status) | ||
return sdkerrs.ErrSdkInternal.Wrap("io.ReadAll(ApiResponse) failed " + err.Error()) | ||
} | ||
log.ZDebug(ctx, "ApiResponse", "url", reqUrl, "status", response.Status, "body", string(respBody)) | ||
var baseApi util.ApiResponse | ||
if err := json.Unmarshal(respBody, &baseApi); err != nil { | ||
return sdkerrs.ErrSdkInternal.Wrap(fmt.Sprintf("api %s json.Unmarshal(%q, %T) failed %s", m.apiAddr, string(respBody), &baseApi, err.Error())) | ||
} | ||
if baseApi.ErrCode != 0 { | ||
err := sdkerrs.New(baseApi.ErrCode, baseApi.ErrMsg, baseApi.ErrDlt) | ||
return err | ||
} | ||
if resp == nil || len(baseApi.Data) == 0 || string(baseApi.Data) == "null" { | ||
return nil | ||
} | ||
if err := json.Unmarshal(baseApi.Data, resp); err != nil { | ||
return sdkerrs.ErrSdkInternal.Wrap(fmt.Sprintf("json.Unmarshal(%q, %T) failed %s", string(baseApi.Data), resp, err.Error())) | ||
} | ||
return nil | ||
} | ||
|
||
func (m *MetaManager) postWithCtx(route string, req, resp any) error { | ||
return m.apiPost(m.buildCtx(), route, req, resp) | ||
} | ||
|
||
func (m *MetaManager) buildCtx() context.Context { | ||
return mcontext.NewCtx(utils.OperationIDGenerator()) | ||
} | ||
|
||
func (m *MetaManager) getToken(userID string, platformID int32) (string, error) { | ||
req := authPB.UserTokenReq{PlatformID: platformID, UserID: userID, Secret: m.secret} | ||
resp := authPB.UserTokenResp{} | ||
err := m.postWithCtx(constant.GetUsersToken, &req, &resp) | ||
if err != nil { | ||
return "", err | ||
} | ||
return resp.Token, nil | ||
} | ||
|
||
func (m *MetaManager) initToken() error { | ||
token, err := m.getToken(m.managerUserID, constant.AdminPlatformID) | ||
if err != nil { | ||
return err | ||
} | ||
m.token = token | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package msgtest | ||
package module | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package module | ||
|
||
import ( | ||
"fmt" | ||
"open_im_sdk/pkg/constant" | ||
"time" | ||
|
||
"github.com/OpenIMSDK/protocol/sdkws" | ||
userPB "github.com/OpenIMSDK/protocol/user" | ||
) | ||
|
||
type TestUserManager struct { | ||
*MetaManager | ||
} | ||
|
||
func (t *TestUserManager) GenUserIDs(num int) (userIDs []string) { | ||
for i := 0; i < num; i++ { | ||
userIDs = append(userIDs, fmt.Sprintf("testv3new_%d_%d", time.Now().UnixNano(), i)) | ||
} | ||
return userIDs | ||
} | ||
|
||
func (t *TestUserManager) RegisterUsers(userIDs ...string) error { | ||
var users []*sdkws.UserInfo | ||
for _, userID := range userIDs { | ||
users = append(users, &sdkws.UserInfo{UserID: userID, Nickname: userID}) | ||
} | ||
return t.postWithCtx(constant.UserRegister, &userPB.UserRegisterReq{ | ||
Secret: t.secret, | ||
Users: users, | ||
}, nil) | ||
} |
Oops, something went wrong.