MCPcopy Create free account
hub / github.com/PasarGuard/node / startXrayProcess

Function startXrayProcess

backend/xray/process_unix_test.go:84–118  ·  view source on GitHub ↗
(t *testing.T, exe string)

Source from the content-addressed store, hash-verified

82}
83
84func startXrayProcess(t *testing.T, exe string) (pid int, waitCh <-chan error) {
85 t.Helper()
86
87 configPath := writeMinimalXrayConfig(t)
88
89 cmd := exec.Command(exe, "-c", configPath)
90 cmd.Env = append(os.Environ(), XrayEnv()...)
91 cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
92
93 if err := cmd.Start(); err != nil {
94 t.Fatalf("failed to start real xray (%s): %v", exe, err)
95 }
96
97 wait := make(chan error, 1)
98 go func() {
99 wait <- cmd.Wait()
100 }()
101
102 // Ensure it didn't exit immediately
103 select {
104 case err := <-wait:
105 t.Fatalf("xray exited early: %v", err)
106 default:
107 }
108
109 t.Cleanup(func() {
110 _ = killProcessTree(cmd.Process.Pid)
111 select {
112 case <-wait:
113 case <-time.After(time.Second):
114 }
115 })
116
117 return cmd.Process.Pid, wait
118}
119
120func writeMinimalXrayConfig(t *testing.T) string {
121 t.Helper()

Callers 1

Calls 4

writeMinimalXrayConfigFunction · 0.85
XrayEnvFunction · 0.85
killProcessTreeFunction · 0.70
StartMethod · 0.65

Tested by

no test coverage detected