package service import ( "testing" ) func TestRestartXrayRespectsManualStop(t *testing.T) { setupSettingTestDB(t) if err := (&SettingService{}).saveSetting("xrayTemplateConfig", "{ not valid json"); err != nil { t.Fatalf("seed template: %v", err) } t.Cleanup(func() { isManuallyStopped.Store(false) }) isManuallyStopped.Store(true) _ = (&XrayService{}).RestartXray(false) if !isManuallyStopped.Load() { t.Fatal("a non-forced restart cleared a deliberate manual stop and would revive xray") } } // The local core never runs in this build, so ApplyPendingRestart no // longer restarts anything and must not re-arm the flag for a retry loop: // it consumes the pending flag and drops it. func TestApplyPendingRestartDropsFlagWithoutLocalCore(t *testing.T) { setupSettingTestDB(t) t.Cleanup(func() { isManuallyStopped.Store(false) isNeedXrayRestart.Store(false) }) isManuallyStopped.Store(false) svc := &XrayService{} svc.SetToNeedRestart() svc.ApplyPendingRestart() if isNeedXrayRestart.Load() { t.Fatal("pending restart must be consumed and dropped; there is no local core to retry against") } }