新增通道服务相关测试用例

This commit is contained in:
2025-04-01 11:32:17 +08:00
parent 87eecdb8cb
commit e4bd86642e
10 changed files with 1249 additions and 69 deletions

View File

@@ -99,6 +99,9 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
proxies, err := tx.Proxy.Where(
q.Proxy.ID.In(proxyIds...),
).Find()
if err != nil {
return err
}
slog.Debug("查找代理", "rid", rid, "step", time.Since(step))
@@ -163,7 +166,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
}
var secret = strings.Split(proxy.Secret, ":")
gateway := remote.InitGateway(
gateway := remote.NewGateway(
proxy.Host,
secret[0],
secret[1],
@@ -204,7 +207,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
}
}
if len(edges) > 0 {
_, err := remote.Client.CloudDisconnect(remote.CloudDisconnectReq{
_, err := remote.Cloud.CloudDisconnect(remote.CloudDisconnectReq{
Uuid: proxy.Name,
Edge: edges,
})
@@ -395,7 +398,7 @@ func assignEdge(count int, filter NodeFilterConfig) (*AssignEdgeResult, error) {
// 查询已配置的节点
step = time.Now()
rProxyConfigs, err := remote.Client.CloudAutoQuery()
rProxyConfigs, err := remote.Cloud.CloudAutoQuery()
if err != nil {
return nil, err
}
@@ -466,7 +469,7 @@ func assignEdge(count int, filter NodeFilterConfig) (*AssignEdgeResult, error) {
step = time.Now()
slog.Debug("新增新节点", "proxy", info.proxy.Name, "used", info.used, "count", info.count)
err := remote.Client.CloudConnect(remote.CloudConnectReq{
err := remote.Cloud.CloudConnect(remote.CloudConnectReq{
Uuid: info.proxy.Name,
Edge: nil,
AutoConfig: []remote.AutoConfig{{
@@ -520,7 +523,7 @@ func assignPort(
expiration time.Time,
filter NodeFilterConfig,
) ([]string, []*models.Channel, error) {
var step = time.Now()
var step time.Time
var configs = proxies.configs
var exists = proxies.channels
@@ -639,7 +642,7 @@ func assignPort(
step = time.Now()
var secret = strings.Split(proxy.Secret, ":")
gateway := remote.InitGateway(
gateway := remote.NewGateway(
proxy.Host,
secret[0],
secret[1],
@@ -677,6 +680,10 @@ func chKey(channel *models.Channel) string {
}
func cache(ctx context.Context, channels []*models.Channel) error {
if len(channels) == 0 {
return nil
}
pipe := rds.Client.TxPipeline()
zList := make([]redis.Z, 0, len(channels))
@@ -685,7 +692,7 @@ func cache(ctx context.Context, channels []*models.Channel) error {
if err != nil {
return err
}
pipe.Set(ctx, chKey(channel), string(marshal), channel.Expiration.Sub(time.Now()))
pipe.Set(ctx, chKey(channel), string(marshal), time.Until(channel.Expiration))
zList = append(zList, redis.Z{
Score: float64(channel.Expiration.Unix()),
Member: channel.ID,
@@ -702,6 +709,10 @@ func cache(ctx context.Context, channels []*models.Channel) error {
}
func deleteCache(ctx context.Context, channels []*models.Channel) error {
if len(channels) == 0 {
return nil
}
keys := make([]string, len(channels))
for i := range channels {
keys[i] = chKey(channels[i])