xray_process_test_seam.go 528 B

12345678910111213141516
  1. package service
  2. import "github.com/mhsanaei/3x-ui/v3/internal/xray"
  3. // SetXrayProcessForTest installs p as the running process and returns the restore func,
  4. // so tests in other packages can observe online state. Never call it in production.
  5. func SetXrayProcessForTest(p *xray.Process) (restore func()) {
  6. previousProcess, previousResult := xrayState.snapshot()
  7. xrayState.replace(p)
  8. return func() {
  9. xrayState.mu.Lock()
  10. xrayState.process = previousProcess
  11. xrayState.result = previousResult
  12. xrayState.mu.Unlock()
  13. }
  14. }