1
0

server_cold_status_test.go 943 B

1234567891011121314151617181920212223242526272829303132
  1. package service
  2. import (
  3. "path/filepath"
  4. "testing"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database/dbtest"
  6. )
  7. // A panel restarts with an empty snapshot until the @2s ticker fires, and a
  8. // master probing that window reads the empty answer as an offline node.
  9. func TestCurrentStatusSamplesBeforeFirstTick(t *testing.T) {
  10. dbDir := t.TempDir()
  11. t.Setenv("XUI_DB_FOLDER", dbDir)
  12. dbtest.InitDB(t, filepath.Join(dbDir, "x-ui.db"))
  13. svc := &ServerService{}
  14. if svc.LastStatus() != nil {
  15. t.Fatal("a fresh ServerService should hold no snapshot yet")
  16. }
  17. status := svc.CurrentStatus()
  18. if status == nil {
  19. t.Fatal("CurrentStatus returned nil before the first ticker run, want an on-demand sample")
  20. }
  21. if svc.LastStatus() != status {
  22. t.Fatal("the on-demand sample should be stored as LastStatus")
  23. }
  24. if again := svc.CurrentStatus(); again != status {
  25. t.Fatal("a warm CurrentStatus should reuse the stored snapshot, not resample")
  26. }
  27. }