mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-16 23:27:14 +00:00
d1c4e0261b
The traffic sync's call that drops online sets of nodes it no longer fetches had no test: a job-package test cannot install an xray process, so online state was invisible there and removing the call passed. SetXrayProcessForTest installs a test process for tests in other packages, the same kind of seam as Manager.SetRuntimeOverride. The new job test runs a real tick with a disabled node and a deleted one and fails without the call.
17 lines
528 B
Go
17 lines
528 B
Go
package service
|
|
|
|
import "github.com/mhsanaei/3x-ui/v3/internal/xray"
|
|
|
|
// SetXrayProcessForTest installs p as the running process and returns the restore func,
|
|
// so tests in other packages can observe online state. Never call it in production.
|
|
func SetXrayProcessForTest(p *xray.Process) (restore func()) {
|
|
previousProcess, previousResult := xrayState.snapshot()
|
|
xrayState.replace(p)
|
|
return func() {
|
|
xrayState.mu.Lock()
|
|
xrayState.process = previousProcess
|
|
xrayState.result = previousResult
|
|
xrayState.mu.Unlock()
|
|
}
|
|
}
|