修改事务提交调用问题
This commit is contained in:
@@ -251,7 +251,7 @@ func (s *channelService) CreateChannel(
|
||||
}
|
||||
|
||||
var addr []*PortInfo
|
||||
err := q.Q.Transaction(func(tx *q.Query) error {
|
||||
err := q.Q.Transaction(func(q *q.Query) error {
|
||||
|
||||
// 查找套餐
|
||||
step = time.Now()
|
||||
@@ -285,7 +285,7 @@ func (s *channelService) CreateChannel(
|
||||
// 申请节点
|
||||
step = time.Now()
|
||||
|
||||
edgeAssigns, err := assignEdge(count, filter)
|
||||
edgeAssigns, err := assignEdge(q, count, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -297,7 +297,7 @@ func (s *channelService) CreateChannel(
|
||||
|
||||
now := time.Now()
|
||||
expiration := now.Add(time.Duration(resource.Live) * time.Second)
|
||||
_addr, channels, err := assignPort(edgeAssigns, auth.Payload.Id, protocol, authType, expiration, filter)
|
||||
_addr, channels, err := assignPort(q, edgeAssigns, auth.Payload.Id, protocol, authType, expiration, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -386,7 +386,7 @@ func checkUser(auth *AuthContext, resource *ResourceInfo, count int) error {
|
||||
}
|
||||
|
||||
// assignEdge 分配边缘节点数量
|
||||
func assignEdge(count int, filter NodeFilterConfig) (*AssignEdgeResult, error) {
|
||||
func assignEdge(q *q.Query, count int, filter NodeFilterConfig) (*AssignEdgeResult, error) {
|
||||
|
||||
// 查询可以使用的网关
|
||||
var step = time.Now()
|
||||
@@ -539,6 +539,7 @@ type ProxyConfig struct {
|
||||
|
||||
// assignPort 分配指定数量的端口
|
||||
func assignPort(
|
||||
q *q.Query,
|
||||
proxies *AssignEdgeResult,
|
||||
userId int32,
|
||||
protocol ChannelProtocol,
|
||||
@@ -718,8 +719,7 @@ func genPassPair() (string, string) {
|
||||
password[i] = letters[rand.N(len(letters))]
|
||||
}
|
||||
|
||||
// return string(username), string(password)
|
||||
return "123123", "123123"
|
||||
return string(username), string(password)
|
||||
}
|
||||
|
||||
func chKey(channel *models.Channel) string {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"platform/pkg/remote"
|
||||
"platform/pkg/testutil"
|
||||
"platform/web/models"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -337,7 +338,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
name string
|
||||
args args
|
||||
setup func()
|
||||
want []string
|
||||
want []*PortInfo
|
||||
wantErr bool
|
||||
wantErrContains string
|
||||
checkCache func(channels []models.Channel) error
|
||||
@@ -353,10 +354,12 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
count: 3,
|
||||
nodeFilter: []NodeFilterConfig{{Prov: "河南", City: "郑州", Isp: "电信"}},
|
||||
},
|
||||
want: []string{
|
||||
"http://111.111.111.111:10000",
|
||||
"http://111.111.111.111:10001",
|
||||
"http://111.111.111.111:10002",
|
||||
want: []*PortInfo{
|
||||
{
|
||||
Proto: "http",
|
||||
Host: proxy.Host,
|
||||
Port: 10000,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -369,10 +372,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
authType: ChannelAuthTypeIp,
|
||||
count: 2,
|
||||
},
|
||||
want: []string{
|
||||
"http://111.111.111.111:10000",
|
||||
"http://111.111.111.111:10001",
|
||||
},
|
||||
want: []*PortInfo{},
|
||||
},
|
||||
{
|
||||
name: "管理员创建SOCKS5密码通道",
|
||||
@@ -384,10 +384,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
authType: ChannelAuthTypePass,
|
||||
count: 2,
|
||||
},
|
||||
want: []string{
|
||||
"socks5://111.111.111.111:10000",
|
||||
"socks5://111.111.111.111:10001",
|
||||
},
|
||||
want: []*PortInfo{},
|
||||
},
|
||||
{
|
||||
name: "套餐不存在",
|
||||
@@ -507,9 +504,9 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(got) != len(tt.want) {
|
||||
t.Errorf("CreateChannel() 返回长度 = %v, want %v", len(got), len(tt.want))
|
||||
return
|
||||
// 检查返回值
|
||||
if reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("CreateChannel() 返回值 = %v, 期望 %v", got, tt.want)
|
||||
}
|
||||
|
||||
// 查询创建的通道
|
||||
|
||||
Reference in New Issue
Block a user