mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-16 23:27:14 +00:00
chore(node): cover the sync tick's online prune from the job package
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.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user