mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-06 14:12:09 +03:00
chore(nodes): run the master+node scopes in parallel and document both layers
Each enrollment scope owns its panels, ports and temp dirs, so the two run side by side; the only shared state, the process-global database handle the harness borrows for setup and for simulating a lost inbound, is now behind a mutex. On Linux the suite drops from 188s to 95s. CLAUDE.md now names the fast contract layer (node_contract_test.go, in make test-go) next to the multi-tick nodee2e layer.
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -93,6 +94,17 @@ func (p *panel) mintToken(name, scope string) string {
|
||||
// newPanel prepares a panel's database: credentials, a private port, its own
|
||||
// sub-server port (two panels on one host would race for 2096) and an admin token.
|
||||
func newPanel(t *testing.T, bin, name string) *panel {
|
||||
t.Helper()
|
||||
p := preparePanel(t, bin, name)
|
||||
p.token = p.mintToken("e2e-driver", "admin")
|
||||
return p
|
||||
}
|
||||
|
||||
// sharedDBMu guards the process-global database handle the harness borrows
|
||||
// while the scopes run in parallel.
|
||||
var sharedDBMu sync.Mutex
|
||||
|
||||
func preparePanel(t *testing.T, bin, name string) *panel {
|
||||
t.Helper()
|
||||
p := &panel{t: t, name: name, bin: bin, dir: t.TempDir(), port: freePort(t)}
|
||||
for _, d := range []string{"db", "log", "bin"} {
|
||||
@@ -101,6 +113,8 @@ func newPanel(t *testing.T, bin, name string) *panel {
|
||||
}
|
||||
}
|
||||
p.cli("setting", "-username", "e2e", "-password", "e2e-pass", "-port", strconv.Itoa(p.port), "-webBasePath", "/")
|
||||
sharedDBMu.Lock()
|
||||
defer sharedDBMu.Unlock()
|
||||
if err := database.InitDB(filepath.Join(p.dir, "db", "x-ui.db")); err != nil {
|
||||
t.Fatalf("%s: open db: %v", name, err)
|
||||
}
|
||||
@@ -112,7 +126,6 @@ func newPanel(t *testing.T, bin, name string) *panel {
|
||||
if err := database.CloseDB(); err != nil {
|
||||
t.Fatalf("%s: close db: %v", name, err)
|
||||
}
|
||||
p.token = p.mintToken("e2e-driver", "admin")
|
||||
t.Cleanup(p.stop)
|
||||
return p
|
||||
}
|
||||
@@ -169,6 +182,8 @@ func (p *panel) deleteInboundRow(id int) {
|
||||
if p.cmd != nil {
|
||||
p.t.Fatalf("%s: deleteInboundRow on a running panel", p.name)
|
||||
}
|
||||
sharedDBMu.Lock()
|
||||
defer sharedDBMu.Unlock()
|
||||
if err := database.InitDB(filepath.Join(p.dir, "db", "x-ui.db")); err != nil {
|
||||
p.t.Fatalf("%s: open db: %v", p.name, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user