mirror of
https://github.com/fatedier/frp.git
synced 2026-10-15 21:26:04 +08:00
fix(server): control work connection refill scheduling
This commit is contained in:
+11
-1
@@ -147,9 +147,19 @@ type NewWorkConn struct {
|
||||
RunID string `json:"run_id,omitempty"`
|
||||
PrivilegeKey string `json:"privilege_key,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
WorkConnType string `json:"work_conn_type,omitempty"`
|
||||
ControlID uint64 `json:"control_id,omitempty"`
|
||||
}
|
||||
|
||||
type ReqWorkConn struct{}
|
||||
const (
|
||||
WorkConnTypeDemand = "demand"
|
||||
WorkConnTypeReserve = "reserve"
|
||||
)
|
||||
|
||||
type ReqWorkConn struct {
|
||||
WorkConnType string `json:"work_conn_type,omitempty"`
|
||||
ControlID uint64 `json:"control_id,omitempty"`
|
||||
}
|
||||
|
||||
type StartWorkConn struct {
|
||||
ProxyName string `json:"proxy_name,omitempty"`
|
||||
|
||||
@@ -19,6 +19,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/fatedier/frp/pkg/proto/wire"
|
||||
)
|
||||
|
||||
func TestV1MessageTypeIDsAreStable(t *testing.T) {
|
||||
@@ -53,3 +55,22 @@ func TestMessageTypeMapIsCompleteAndUnique(t *testing.T) {
|
||||
msgTypes[msgType] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkConnRequestTypeRoundTrip(t *testing.T) {
|
||||
in := &ReqWorkConn{WorkConnType: WorkConnTypeReserve, ControlID: 7}
|
||||
out, err := DecodeV2MessageFrame(mustEncodeV2MessageFrame(t, in))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, in, out)
|
||||
|
||||
inNew := &NewWorkConn{RunID: "run", WorkConnType: WorkConnTypeDemand, ControlID: 7}
|
||||
outNew, err := DecodeV2MessageFrame(mustEncodeV2MessageFrame(t, inNew))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, inNew, outNew)
|
||||
}
|
||||
|
||||
func mustEncodeV2MessageFrame(t *testing.T, m Message) *wire.Frame {
|
||||
t.Helper()
|
||||
frame, err := EncodeV2MessageFrame(m)
|
||||
require.NoError(t, err)
|
||||
return frame
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user