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:
1 parent
f843fe5570
commit
dae91276aa
4 files changed
+21
-82
No files matched your search
@@ -195,8 +195,10 @@ That is the *fast* gate, not all of CI. `ci.yml` also runs `make race`,
|
||||
`make vulncheck`, a live-Postgres job (where a SKIP counts as a failure),
|
||||
`make node-e2e` (a real master and node panel, `internal/nodee2e/`) and a
|
||||
30s fuzz smoke on `FuzzParseLink`/`FuzzDecodeCertPin` — run those locally when
|
||||
you touch DB/dialect, node sync or parser code. A new node-sync behaviour gets
|
||||
a cell in `internal/nodee2e/node_sync_test.go`.
|
||||
you touch DB/dialect, node sync or parser code. Node sync has two layers: every
|
||||
`runtime.Remote` call gets a cell in `internal/web/node_contract_test.go` (fast,
|
||||
in `make test-go`; a method without one fails it), and a multi-tick flow (cron,
|
||||
adopt, node down) gets one in `internal/nodee2e/node_sync_test.go`.
|
||||
|
||||
Common targets: `make gen` (regenerate Zod/OpenAPI), `make lint` (Go + frontend),
|
||||
`make test` (Go `-shuffle=on` + frontend), `make race`, `make build`. See `Makefile`.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestNodeSync(t *testing.T) {
|
||||
bin := panelBinary(t)
|
||||
for _, scope := range []string{"admin", "node-sync"} {
|
||||
t.Run("enrolled with "+scope+" token", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
runNodeSyncScenarios(t, bin, scope)
|
||||
})
|
||||
}
|
||||
|
||||
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user