Files
l-ui/internal/xray/process_version_test.go
Muse 6a5ee8f77b rename: 3x-ui/x-ui -> L-UI/l-ui/lui-agent (paths, services, env, assets)
Display L-UI; panel binary/process l-ui, agent lui-agent.
Dirs /usr/local/l-ui, /etc/l-ui, /var/log/l-ui; DB /etc/l-ui/l-ui.db
(name file drives it via GetName), probe.db beside it, cert
/etc/l-ui/cert, bin /usr/local/l-ui/bin. Services l-ui.service /
lui-agent.service, OpenRC lui-agent, l-ui.sh, cmd/lui-agent.
Env prefix XUI_ -> LUI_ (code reads new prefix only). Release
assets l-ui-linux-* / lui-agent-linux-*; Gitea repo rogue/l-ui is
a placeholder pending user confirmation (see selfupdate.go note).
Go module path github.com/mhsanaei/3x-ui/v3 intentionally kept.
Versions unchanged: panel V2.6.0 / agent A2.5.0.
2026-10-24 12:00:55 +00:00

66 lines
1.4 KiB
Go

package xray
import (
"os"
"path/filepath"
"runtime"
"sync"
"testing"
"time"
)
func TestRefreshVersionTimesOut(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("shell fixture is Unix-only")
}
dir := t.TempDir()
t.Setenv("LUI_BIN_FOLDER", dir)
binaryPath := filepath.Join(dir, GetBinaryName())
if err := os.WriteFile(binaryPath, []byte("#!/bin/sh\nexec sleep 1\n"), 0o700); err != nil {
t.Fatalf("write xray fixture: %v", err)
}
previousTimeout := xrayVersionTimeout
xrayVersionTimeout = 20 * time.Millisecond
t.Cleanup(func() { xrayVersionTimeout = previousTimeout })
p := newProcess(&Config{})
started := time.Now()
p.refreshVersion()
elapsed := time.Since(started)
if elapsed < xrayVersionTimeout {
t.Fatalf("refreshVersion duration = %s, want at least %s", elapsed, xrayVersionTimeout)
}
if elapsed > 500*time.Millisecond {
t.Fatalf("refreshVersion duration = %s, want under 500ms", elapsed)
}
if got := p.GetXrayVersion(); got != "Unknown" {
t.Fatalf("version = %q, want Unknown", got)
}
}
func TestProcessConfigSnapshotsAreRaceSafe(t *testing.T) {
p := NewProcess(&Config{})
first := &Config{}
second := &Config{}
var wg sync.WaitGroup
wg.Go(func() {
for range 1000 {
p.SetConfig(first)
p.SetConfig(second)
}
})
for range 4 {
wg.Go(func() {
for range 1000 {
if p.GetConfig() == nil {
t.Error("config = nil")
}
}
})
}
wg.Wait()
}