Files
3x-ui/internal/web/service/server_cold_status_test.go
T
VAIO73 be25314157 fix(monitoring): refresh cached public IP addresses (#6933)
The public IPv4/IPv6 lookup was cached for the life of the panel process, so
Overview kept showing an old address after the server's external IP changed,
and a failed first lookup pinned N/A until a restart. Addresses now refresh
every five minutes, a failed IPv4 lookup retries after a minute, failed IPv6
lookups back off 1/2/5/15 minutes, and a temporary failure keeps the last
known address. Status sampling still never waits on the lookup.
2026-10-25 13:50:29 +01:00

36 lines
1.2 KiB
Go

package service
import (
"path/filepath"
"testing"
"time"
"github.com/mhsanaei/3x-ui/v3/internal/database/dbtest"
)
// A panel restarts with an empty snapshot until the @2s ticker fires, and a
// master probing that window reads the empty answer as an offline node.
func TestCurrentStatusSamplesBeforeFirstTick(t *testing.T) {
dbDir := t.TempDir()
t.Setenv("XUI_DB_FOLDER", dbDir)
dbtest.InitDB(t, filepath.Join(dbDir, "x-ui.db"))
// A settled IP cache keeps GetStatus from starting a public-IP resolver that
// outlives this test and races http.DefaultTransport in later ones.
svc := &ServerService{cachedIPv4: "192.0.2.1", cachedIPv6: "N/A", nextIPv4Lookup: time.Now().Add(time.Hour), nextIPv6Lookup: time.Now().Add(time.Hour)}
if svc.LastStatus() != nil {
t.Fatal("a fresh ServerService should hold no snapshot yet")
}
status := svc.CurrentStatus()
if status == nil {
t.Fatal("CurrentStatus returned nil before the first ticker run, want an on-demand sample")
}
if svc.LastStatus() != status {
t.Fatal("the on-demand sample should be stored as LastStatus")
}
if again := svc.CurrentStatus(); again != status {
t.Fatal("a warm CurrentStatus should reuse the stored snapshot, not resample")
}
}