|
|
@ -3,100 +3,102 @@ package cronTask
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
|
|
|
|
pbMsg "Open_IM/pkg/proto/msg"
|
|
|
|
|
|
|
|
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
|
|
|
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"context"
|
|
|
|
"os/exec"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func getMsgListFake(num int) []*pbMsg.MsgDataToMQ {
|
|
|
|
var (
|
|
|
|
var msgList []*pbMsg.MsgDataToMQ
|
|
|
|
redisClient *redis.Client
|
|
|
|
for i := 1; i < num; i++ {
|
|
|
|
mongoClient *mongo.Collection
|
|
|
|
msgList = append(msgList, &pbMsg.MsgDataToMQ{
|
|
|
|
)
|
|
|
|
Token: "tk",
|
|
|
|
|
|
|
|
OperationID: "operationID",
|
|
|
|
func GenUserChat(startSeq, stopSeq, delSeq, index uint32, userID string) *db.UserChat {
|
|
|
|
MsgData: &server_api_params.MsgData{
|
|
|
|
chat := &db.UserChat{UID: userID + strconv.Itoa(int(index))}
|
|
|
|
SendID: "sendID1",
|
|
|
|
for i := startSeq; i <= stopSeq; i++ {
|
|
|
|
RecvID: "recvID1",
|
|
|
|
msg := server_api_params.MsgData{
|
|
|
|
GroupID: "",
|
|
|
|
SendID: "sendID1",
|
|
|
|
ClientMsgID: "xxx",
|
|
|
|
RecvID: "recvID1",
|
|
|
|
ServerMsgID: "xxx",
|
|
|
|
GroupID: "",
|
|
|
|
SenderPlatformID: 1,
|
|
|
|
ClientMsgID: "xxx",
|
|
|
|
SenderNickname: "testNickName",
|
|
|
|
ServerMsgID: "xxx",
|
|
|
|
SenderFaceURL: "testFaceURL",
|
|
|
|
SenderPlatformID: 1,
|
|
|
|
SessionType: 1,
|
|
|
|
SenderNickname: "testNickName",
|
|
|
|
MsgFrom: 100,
|
|
|
|
SenderFaceURL: "testFaceURL",
|
|
|
|
ContentType: 101,
|
|
|
|
SessionType: 1,
|
|
|
|
Content: []byte("testFaceURL"),
|
|
|
|
MsgFrom: 100,
|
|
|
|
Seq: uint32(i),
|
|
|
|
ContentType: 101,
|
|
|
|
SendTime: time.Now().Unix(),
|
|
|
|
Content: []byte("testFaceURL"),
|
|
|
|
CreateTime: time.Now().Unix(),
|
|
|
|
Seq: uint32(i),
|
|
|
|
Status: 1,
|
|
|
|
SendTime: time.Now().Unix(),
|
|
|
|
},
|
|
|
|
CreateTime: time.Now().Unix(),
|
|
|
|
})
|
|
|
|
Status: 1,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes, _ := proto.Marshal(&msg)
|
|
|
|
|
|
|
|
sendTime := 0
|
|
|
|
|
|
|
|
chat.Msg = append(chat.Msg, db.MsgInfo{SendTime: int64(sendTime), Msg: bytes})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return msgList
|
|
|
|
return chat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) {
|
|
|
|
func SetUserMaxSeq(userID string, seq int) error {
|
|
|
|
|
|
|
|
return redisClient.Set(context.Background(), "REDIS_USER_INCR_SEQ"+userID, seq, 0).Err()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func CreateChat(userChat *db.UserChat) error {
|
|
|
|
|
|
|
|
_, err := mongoClient.InsertOne(context.Background(), userChat)
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) {
|
|
|
|
operationID := getCronTaskOperationID()
|
|
|
|
operationID := getCronTaskOperationID()
|
|
|
|
|
|
|
|
redisClient = redis.NewClient(&redis.Options{
|
|
|
|
|
|
|
|
Addr: "127.0.0.1:16379",
|
|
|
|
|
|
|
|
Password: "openIM123", // no password set
|
|
|
|
|
|
|
|
DB: 13, // use default DB
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
mongoUri := fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d&authSource=admin",
|
|
|
|
|
|
|
|
"root", "openIM123", "127.0.0.1:37017",
|
|
|
|
|
|
|
|
"openIM", 100)
|
|
|
|
|
|
|
|
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(mongoUri))
|
|
|
|
|
|
|
|
mongoClient = client.Database("openIM").Collection("msg")
|
|
|
|
testUID1 := "test_del_id1"
|
|
|
|
testUID1 := "test_del_id1"
|
|
|
|
//testUID2 := "test_del_id2"
|
|
|
|
//testUID2 := "test_del_id2"
|
|
|
|
//testUID3 := "test_del_id3"
|
|
|
|
//testUID3 := "test_del_id3"
|
|
|
|
//testUID4 := "test_del_id4"
|
|
|
|
//testUID4 := "test_del_id4"
|
|
|
|
//testUID5 := "test_del_id5"
|
|
|
|
//testUID5 := "test_del_id5"
|
|
|
|
//testUID6 := "test_del_id6"
|
|
|
|
//testUID6 := "test_del_id6"
|
|
|
|
testUserIDList := []string{testUID1}
|
|
|
|
err = SetUserMaxSeq(testUID1, 600)
|
|
|
|
|
|
|
|
userChat := GenUserChat(1, 500, 200, 0, testUID1)
|
|
|
|
|
|
|
|
err = CreateChat(userChat)
|
|
|
|
|
|
|
|
|
|
|
|
err := db.DB.SetUserMaxSeq(testUID1, 500)
|
|
|
|
if err := DeleteMongoMsgAndResetRedisSeq(operationID, testUID1); err != nil {
|
|
|
|
err = db.DB.BatchInsertChat2DB(testUID1, getMsgListFake(500), testUID1+"-"+operationID, 500)
|
|
|
|
t.Error("checkMaxSeqWithMongo failed", testUID1)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Error(err.Error(), testUID1)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//db.DB.SetUserMaxSeq(testUID1, 6000)
|
|
|
|
if err := checkMaxSeqWithMongo(operationID, testUID1, constant.WriteDiffusion); err != nil {
|
|
|
|
//db.DB.BatchInsertChat2DB()
|
|
|
|
t.Error("checkMaxSeqWithMongo failed", testUID1)
|
|
|
|
//
|
|
|
|
|
|
|
|
//db.DB.SetUserMaxSeq(testUID1, 4999)
|
|
|
|
|
|
|
|
//db.DB.BatchInsertChat2DB()
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//db.DB.SetUserMaxSeq(testUID1, 30000)
|
|
|
|
|
|
|
|
//db.DB.BatchInsertChat2DB()
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//db.DB.SetUserMaxSeq(testUID1, 9999)
|
|
|
|
|
|
|
|
//db.DB.BatchInsertChat2DB()
|
|
|
|
|
|
|
|
cmd := exec.Command("/bin/bash", "unset $CONFIG_NAME")
|
|
|
|
|
|
|
|
_, err = cmd.StdoutPipe()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//执行命令
|
|
|
|
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, userID := range testUserIDList {
|
|
|
|
|
|
|
|
operationID = userID + "-" + operationID
|
|
|
|
|
|
|
|
if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil {
|
|
|
|
|
|
|
|
t.Error("checkMaxSeqWithMongo failed", userID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := checkMaxSeqWithMongo(operationID, userID, constant.WriteDiffusion); err != nil {
|
|
|
|
|
|
|
|
t.Error("checkMaxSeqWithMongo failed", userID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
testWorkingGroupIDList := []string{"test_del_id1", "test_del_id2", "test_del_id3", "test_del_id4", "test_del_id5"}
|
|
|
|
t.Error("err is not nil", testUID1, err.Error())
|
|
|
|
for _, groupID := range testWorkingGroupIDList {
|
|
|
|
|
|
|
|
operationID = groupID + "-" + operationID
|
|
|
|
|
|
|
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "groupID:", groupID, "userIDList:", testUserIDList)
|
|
|
|
|
|
|
|
if err := ResetUserGroupMinSeq(operationID, groupID, testUserIDList); err != nil {
|
|
|
|
|
|
|
|
t.Error("checkMaxSeqWithMongo failed", groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := checkMaxSeqWithMongo(operationID, groupID, constant.ReadDiffusion); err != nil {
|
|
|
|
|
|
|
|
t.Error("checkMaxSeqWithMongo failed", groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// testWorkingGroupIDList := []string{"test_del_id1", "test_del_id2", "test_del_id3", "test_del_id4", "test_del_id5"}
|
|
|
|
|
|
|
|
// for _, groupID := range testWorkingGroupIDList {
|
|
|
|
|
|
|
|
// operationID = groupID + "-" + operationID
|
|
|
|
|
|
|
|
// log.NewDebug(operationID, utils.GetSelfFuncName(), "groupID:", groupID, "userIDList:", testUserIDList)
|
|
|
|
|
|
|
|
// if err := ResetUserGroupMinSeq(operationID, groupID, testUserIDList); err != nil {
|
|
|
|
|
|
|
|
// t.Error("checkMaxSeqWithMongo failed", groupID)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if err := checkMaxSeqWithMongo(operationID, groupID, constant.ReadDiffusion); err != nil {
|
|
|
|
|
|
|
|
// t.Error("checkMaxSeqWithMongo failed", groupID)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|