mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 00:15:09 +03:00
perf(clients): batch client creation by destination node
Group compatible committed adds into the existing multi-inbound request. Keep lane ordering, preserve target-specific payloads, and bound remote delivery across the create so unavailable nodes can converge through reconciliation.
This commit is contained in:
@@ -39,7 +39,7 @@ func TestNodeSnapshotVersionCompatibility(t *testing.T) {
|
||||
token := node.mintToken("snapshot-link", "node-sync")
|
||||
master.start()
|
||||
node.start()
|
||||
var lists, compact, full, unchanged atomic.Int32
|
||||
var lists, compact, full, unchanged, clientAdds atomic.Int32
|
||||
target, err := url.Parse(node.url())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -88,6 +88,8 @@ func TestNodeSnapshotVersionCompatibility(t *testing.T) {
|
||||
lists.Add(1)
|
||||
case "/panel/api/inbounds/trafficSnapshot":
|
||||
compact.Add(1)
|
||||
case "/panel/api/clients/add":
|
||||
clientAdds.Add(1)
|
||||
}
|
||||
proxy.ServeHTTP(w, req)
|
||||
}))
|
||||
@@ -101,10 +103,14 @@ func TestNodeSnapshotVersionCompatibility(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inboundPort := freePort(t)
|
||||
secondaryPort := freePort(t)
|
||||
var source inboundView
|
||||
if err := json.Unmarshal(node.call(http.MethodPost, "/panel/api/inbounds/add", vlessInbound("matrix", inboundPort, nil, vlessClient("matrix-first"))), &source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if version.master == current {
|
||||
node.call(http.MethodPost, "/panel/api/inbounds/add", vlessInbound("matrix-secondary", secondaryPort, nil))
|
||||
}
|
||||
master.call(http.MethodPost, "/panel/api/nodes/add", map[string]any{"name": "matrix-node", "scheme": "http", "address": address.Hostname(), "port": port, "basePath": "/", "apiToken": token, "enable": true, "allowPrivateAddress": true})
|
||||
eventually(t, settleTimeout, "version pair synchronizes and reaches steady state", func() (bool, string) {
|
||||
ib, ok := master.inboundOnPort(inboundPort)
|
||||
@@ -136,6 +142,25 @@ func TestNodeSnapshotVersionCompatibility(t *testing.T) {
|
||||
master.start()
|
||||
eventually(t, settleTimeout, "master restart reacquires complete structure", func() (bool, string) { return full.Load() > before, fmt.Sprint(full.Load()) })
|
||||
}
|
||||
if version.master == current {
|
||||
first, hasFirst := master.inboundOnPort(inboundPort)
|
||||
second, hasSecond := master.inboundOnPort(secondaryPort)
|
||||
if !hasFirst || !hasSecond {
|
||||
t.Fatal("master did not adopt both inbounds")
|
||||
}
|
||||
const email = "matrix-shared-create"
|
||||
master.call(http.MethodPost, "/panel/api/clients/add", map[string]any{
|
||||
"client": map[string]any{"email": email, "enable": true}, "inboundIds": []int{first.Id, second.Id},
|
||||
})
|
||||
if got := clientAdds.Load(); got != 1 {
|
||||
t.Fatalf("node-sync received %d add requests, want one", got)
|
||||
}
|
||||
for _, port := range []int{inboundPort, secondaryPort} {
|
||||
if ib, ok := node.inboundOnPort(port); !ok || ib.client(email) == nil {
|
||||
t.Fatalf("node did not apply the grouped client on port %d", port)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user