mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-07-06 20:03:23 +08:00
* fix: performance issues with Kafka caused by encapsulating the MQ interface * fix: admin token in standalone mode * fix: full id version * fix: resolve deadlock in cache eviction and improve GetBatch implementation * refactor: replace LongConn with ClientConn interface and simplify message handling * refactor: replace LongConn with ClientConn interface and simplify message handling * fix: seq use $setOnInsert for min_seq in conversation update * feat: add error code for handled friend requests and improve error handling in friend operations * refactor(msg): update regex pattern for conversationID to include a trailing colon * refactor: streamline cache initialization and enhance queue engine configuration * refactor: streamline cache initialization and enhance queue engine configuration * feat: add RegisterIP to API config and implement Redis server registration * feat(redis): implement standalone gateway registration with Redis * chore: update openimsdk/tools dependency to v0.0.50-alpha.121 * fix: change timer to ticker for improved periodic execution * refactor: replace Kafka topic configuration with mqbuild constants for improved readability * feat(redis): implement Redis-based locking mechanism for cron tasks
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/go-redis/redismock/v9"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStandaloneGatewayRedisRegisterGateway(t *testing.T) {
|
|
rdb, mock := redismock.NewClientMock()
|
|
cache := NewStandaloneGatewayRedis(rdb, time.Second*10)
|
|
|
|
mock.Regexp().ExpectHSet(standaloneGatewayHashKey, "127.0.0.1:10001", `^[0-9]+$`).SetVal(1)
|
|
mock.ExpectExpire(standaloneGatewayHashKey, time.Second*20).SetVal(true)
|
|
|
|
err := cache.RegisterGateway(context.Background(), "127.0.0.1:10001")
|
|
require.NoError(t, err)
|
|
assert.NoError(t, mock.ExpectationsWereMet())
|
|
}
|
|
|
|
func TestStandaloneGatewayRedisUnregisterGateway(t *testing.T) {
|
|
rdb, mock := redismock.NewClientMock()
|
|
cache := NewStandaloneGatewayRedis(rdb, time.Second)
|
|
|
|
mock.ExpectHDel(standaloneGatewayHashKey, "127.0.0.1:10001").SetVal(1)
|
|
|
|
err := cache.UnregisterGateway(context.Background(), "127.0.0.1:10001")
|
|
require.NoError(t, err)
|
|
assert.NoError(t, mock.ExpectationsWereMet())
|
|
}
|
|
|
|
func TestStandaloneGatewayRedisGetGatewayAddrs(t *testing.T) {
|
|
rdb, mock := redismock.NewClientMock()
|
|
cache := NewStandaloneGatewayRedis(rdb, time.Second*10)
|
|
|
|
now := time.Now()
|
|
mock.ExpectHGetAll(standaloneGatewayHashKey).SetVal(map[string]string{
|
|
"127.0.0.1:10001": strconv.FormatInt(now.Add(-time.Second).UnixMilli(), 10),
|
|
"127.0.0.1:10002": strconv.FormatInt(now.Add(-time.Second*20).UnixMilli(), 10),
|
|
"127.0.0.1:10003": strconv.FormatInt(now.Add(time.Second).UnixMilli(), 10),
|
|
})
|
|
|
|
addrs, err := cache.GetGatewayAddrs(context.Background())
|
|
require.NoError(t, err)
|
|
assert.ElementsMatch(t, []string{"127.0.0.1:10001", "127.0.0.1:10003"}, addrs)
|
|
assert.NoError(t, mock.ExpectationsWereMet())
|
|
}
|