xray_restart_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package service
  2. import (
  3. "testing"
  4. )
  5. func TestRestartXrayRespectsManualStop(t *testing.T) {
  6. setupSettingTestDB(t)
  7. if err := (&SettingService{}).saveSetting("xrayTemplateConfig", "{ not valid json"); err != nil {
  8. t.Fatalf("seed template: %v", err)
  9. }
  10. t.Cleanup(func() { isManuallyStopped.Store(false) })
  11. isManuallyStopped.Store(true)
  12. _ = (&XrayService{}).RestartXray(false)
  13. if !isManuallyStopped.Load() {
  14. t.Fatal("a non-forced restart cleared a deliberate manual stop and would revive xray")
  15. }
  16. }
  17. func TestApplyPendingRestartReArmsFlagOnFailure(t *testing.T) {
  18. setupSettingTestDB(t)
  19. if err := (&SettingService{}).saveSetting("xrayTemplateConfig", "{ not valid json"); err != nil {
  20. t.Fatalf("seed template: %v", err)
  21. }
  22. t.Cleanup(func() {
  23. isManuallyStopped.Store(false)
  24. isNeedXrayRestart.Store(false)
  25. })
  26. isManuallyStopped.Store(false)
  27. svc := &XrayService{}
  28. svc.SetToNeedRestart()
  29. svc.ApplyPendingRestart()
  30. if !isNeedXrayRestart.Load() {
  31. t.Fatal("a failed restart must re-arm the need-restart flag so the pending config change is retried")
  32. }
  33. }