mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-28 14:56:33 -04:00
remove unused code
This commit is contained in:
parent
fbd035247f
commit
e128f4de42
@ -1,14 +1,23 @@
|
|||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
|
"v2ray.com/core/app/log"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
|
"v2ray.com/core/common/retry"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pickPort() v2net.Port {
|
func pickPort() v2net.Port {
|
||||||
@ -59,3 +68,46 @@ func InitializeServerConfig(config *core.Config) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
runningServers = make([]*exec.Cmd, 0, 10)
|
||||||
|
testBinaryPath string
|
||||||
|
testBinaryPathGen sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
|
func genTestBinaryPath() {
|
||||||
|
testBinaryPathGen.Do(func() {
|
||||||
|
var tempDir string
|
||||||
|
err := retry.Timed(5, 100).On(func() error {
|
||||||
|
dir, err := ioutil.TempDir("", "v2ray")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tempDir = dir
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
file := filepath.Join(tempDir, "v2ray.test")
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
file += ".exe"
|
||||||
|
}
|
||||||
|
testBinaryPath = file
|
||||||
|
fmt.Printf("Generated binary path: %s\n", file)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSourcePath() string {
|
||||||
|
return filepath.Join("v2ray.com", "core", "main")
|
||||||
|
}
|
||||||
|
|
||||||
|
func CloseAllServers() {
|
||||||
|
log.Info("Closing all servers.")
|
||||||
|
for _, server := range runningServers {
|
||||||
|
server.Process.Signal(os.Interrupt)
|
||||||
|
server.Process.Wait()
|
||||||
|
}
|
||||||
|
runningServers = make([]*exec.Cmd, 0, 10)
|
||||||
|
log.Info("All server closed.")
|
||||||
|
}
|
||||||
|
@ -3,16 +3,16 @@
|
|||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"bytes"
|
|
||||||
"v2ray.com/core/common/uuid"
|
"v2ray.com/core/common/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildV2Ray() error {
|
func BuildV2Ray() error {
|
||||||
GenTestBinaryPath()
|
genTestBinaryPath()
|
||||||
if _, err := os.Stat(testBinaryPath); err == nil {
|
if _, err := os.Stat(testBinaryPath); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -21,21 +21,8 @@ func BuildV2Ray() error {
|
|||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunV2Ray(configFile string) *exec.Cmd {
|
|
||||||
GenTestBinaryPath()
|
|
||||||
|
|
||||||
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
|
|
||||||
os.MkdirAll(covDir, os.ModeDir)
|
|
||||||
profile := uuid.New().String() + ".out"
|
|
||||||
proc := exec.Command(testBinaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
|
|
||||||
proc.Stderr = os.Stderr
|
|
||||||
proc.Stdout = os.Stdout
|
|
||||||
|
|
||||||
return proc
|
|
||||||
}
|
|
||||||
|
|
||||||
func RunV2RayProtobuf(config []byte) *exec.Cmd {
|
func RunV2RayProtobuf(config []byte) *exec.Cmd {
|
||||||
GenTestBinaryPath()
|
genTestBinaryPath()
|
||||||
|
|
||||||
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
|
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
|
||||||
os.MkdirAll(covDir, os.ModeDir)
|
os.MkdirAll(covDir, os.ModeDir)
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BuildV2Ray() error {
|
func BuildV2Ray() error {
|
||||||
GenTestBinaryPath()
|
genTestBinaryPath()
|
||||||
if _, err := os.Stat(testBinaryPath); err == nil {
|
if _, err := os.Stat(testBinaryPath); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -20,17 +20,8 @@ func BuildV2Ray() error {
|
|||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunV2Ray(configFile string) *exec.Cmd {
|
|
||||||
GenTestBinaryPath()
|
|
||||||
proc := exec.Command(testBinaryPath, "-config", configFile)
|
|
||||||
proc.Stderr = os.Stderr
|
|
||||||
proc.Stdout = os.Stdout
|
|
||||||
|
|
||||||
return proc
|
|
||||||
}
|
|
||||||
|
|
||||||
func RunV2RayProtobuf(config []byte) *exec.Cmd {
|
func RunV2RayProtobuf(config []byte) *exec.Cmd {
|
||||||
GenTestBinaryPath()
|
genTestBinaryPath()
|
||||||
proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb")
|
proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb")
|
||||||
proc.Stdin = bytes.NewBuffer(config)
|
proc.Stdin = bytes.NewBuffer(config)
|
||||||
proc.Stderr = os.Stderr
|
proc.Stderr = os.Stderr
|
@ -1,102 +0,0 @@
|
|||||||
package scenarios
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"v2ray.com/core/app/log"
|
|
||||||
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"sync"
|
|
||||||
_ "v2ray.com/core"
|
|
||||||
"v2ray.com/core/common/retry"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
runningServers = make([]*exec.Cmd, 0, 10)
|
|
||||||
testBinaryPath string
|
|
||||||
testBinaryPathGen sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
func GenTestBinaryPath() {
|
|
||||||
testBinaryPathGen.Do(func() {
|
|
||||||
var tempDir string
|
|
||||||
err := retry.Timed(5, 100).On(func() error {
|
|
||||||
dir, err := ioutil.TempDir("", "v2ray")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tempDir = dir
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
file := filepath.Join(tempDir, "v2ray.test")
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
file += ".exe"
|
|
||||||
}
|
|
||||||
testBinaryPath = file
|
|
||||||
fmt.Printf("Generated binary path: %s\n", file)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSourcePath() string {
|
|
||||||
return filepath.Join("v2ray.com", "core", "main")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFile(filename string) string {
|
|
||||||
return filepath.Join(os.Getenv("GOPATH"), "src", "v2ray.com", "core", "testing", "scenarios", "data", filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitializeServerSetOnce(testcase string) error {
|
|
||||||
if err := InitializeServerServer(testcase); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := InitializeServerClient(testcase); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitializeServerServer(testcase string) error {
|
|
||||||
return InitializeServer(TestFile(testcase + "_server.json"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitializeServerClient(testcase string) error {
|
|
||||||
return InitializeServer(TestFile(testcase + "_client.json"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitializeServer(configFile string) error {
|
|
||||||
err := BuildV2Ray()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
proc := RunV2Ray(configFile)
|
|
||||||
|
|
||||||
err = proc.Start()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
runningServers = append(runningServers, proc)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CloseAllServers() {
|
|
||||||
log.Info("Closing all servers.")
|
|
||||||
for _, server := range runningServers {
|
|
||||||
server.Process.Signal(os.Interrupt)
|
|
||||||
server.Process.Wait()
|
|
||||||
}
|
|
||||||
runningServers = make([]*exec.Cmd, 0, 10)
|
|
||||||
log.Info("All server closed.")
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user