mirror of
https://gitcode.com/JianFeeeee/webui4frpc.git
synced 2026-09-20 00:47:57 +00:00
- 主题: sakura×frost 玻璃拟态 (theme.css) + SCSS 变量重映射 - 侧栏: 玻璃侧栏 246px + 渐变品牌区 + 面包屑导航 - 状态页: 玻璃 KPI 卡 + 远程节点/本地服务卡片网格 - 集群页: 英雄玻璃卡 + 横向环拓扑链 + 待办命令/活跃拓扑/日志区 - 令牌环: 新增 lastSync 上次同步时间替代周期计数 - 模拟 frps: frps2/frps3 容器 + test-forward.sh 全链路验证脚本 - 修复: BinaryPath 空导致 worker 不启动, 撤销仅撤第一个 link, 任务复活风暴 (published 追踪)
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package cluster
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
type fakeHandler struct {
|
|
load Load
|
|
claim func(ctx context.Context, tk *Task) error
|
|
revoke func(ctx context.Context, tk *Task) error
|
|
}
|
|
|
|
func (h *fakeHandler) Revoke(ctx context.Context, tk *Task) error {
|
|
if h.revoke != nil {
|
|
return h.revoke(ctx, tk)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (h *fakeHandler) RuntimeLoad() Load { return h.load }
|
|
func (h *fakeHandler) Claim(ctx context.Context, tk *Task) error {
|
|
if h.claim != nil {
|
|
return h.claim(ctx, tk)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// sendNull is a no-op sender (single-node ring).
|
|
func sendNull(ctx context.Context, next string, tk *Token) error { return nil }
|
|
|
|
// TestSingleNodeCycle: leader starts ring, processes phases locally, and the
|
|
// task gets claimed (lowest load = only node).
|
|
func TestSingleNodeCycle(t *testing.T) {
|
|
eng := NewEngine("n1", "n1:7500", "u", "p", "0.71.0", []string{"0.71.0"},
|
|
&fakeHandler{load: Load{MemPct: 30, NetPct: 30}}, sendNull, "n1:7500", true)
|
|
eng.StartRing(context.Background())
|
|
|
|
// single node: token stays local; no successor so nothing travels.
|
|
if eng.State().Nodes[0].ID != "n1" {
|
|
t.Fatalf("nodes = %+v", eng.State().Nodes)
|
|
}
|
|
}
|
|
|
|
// TestTwoNodesPhaseCollect: leader n1 sends to n2; n1 collects both after n2
|
|
// stamps; then phase flips and second round syncs.
|
|
func TestTwoNodesSingleRound(t *testing.T) {
|
|
eng2 := NewEngine("n2", "n2:7500", "u", "p", "0.71.0", nil,
|
|
&fakeHandler{load: Load{MemPct: 10, NetPct: 10}}, sendNull, "n2:7500", false)
|
|
eng2.state.UpsertNode(Node{ID: "n1", Addr: "n1:7500", Alive: true, IsLeader: true, Load: Load{MemPct: 50, NetPct: 50}})
|
|
|
|
// n1 sends a token carrying the cluster picture; single-round processing:
|
|
// the receiving node adopts it and appends its own info in one pass.
|
|
tk := &Token{Cycle: 1, State: State{
|
|
Nodes: []Node{
|
|
{ID: "n1", Addr: "n1:7500", Alive: true, IsLeader: true},
|
|
{ID: "n2", Addr: "n2:7500", Alive: true},
|
|
},
|
|
}}
|
|
|
|
out, err := eng2.OnToken(context.Background(), tk)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if eng2.State().Find("n2") < 0 {
|
|
t.Fatal("n2 should be present in adopted state after single-round")
|
|
}
|
|
if out == nil {
|
|
t.Fatal("nil token after processing")
|
|
}
|
|
}
|