(t *testing.T, exe string)
| 82 | } |
| 83 | |
| 84 | func 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 | |
| 120 | func writeMinimalXrayConfig(t *testing.T) string { |
| 121 | t.Helper() |
no test coverage detected