mirror of
https://github.com/fatedier/frp.git
synced 2026-03-21 09:19:19 +08:00
test/e2e: optimize e2e test time by replacing sleeps with TCP readiness checks (#5223)
Replace the fixed 500ms sleep after each frps startup in RunProcesses with a TCP dial-based readiness check that polls the server bind port. This reduces the e2e suite wall time from ~97s to ~43s. Also simplify the RunProcesses API to accept a single server template string instead of a slice, matching how every call site uses it.
This commit is contained in:
@@ -36,7 +36,7 @@ var _ = ginkgo.Describe("[Feature: Bandwidth Limit]", func() {
|
||||
transport.bandwidthLimit = "10KB"
|
||||
`, localPort, remotePort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
content := strings.Repeat("a", 50*1024) // 5KB
|
||||
start := time.Now()
|
||||
@@ -92,7 +92,7 @@ var _ = ginkgo.Describe("[Feature: Bandwidth Limit]", func() {
|
||||
remotePort = %d
|
||||
`, localPort, remotePort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
content := strings.Repeat("a", 50*1024) // 5KB
|
||||
start := time.Now()
|
||||
|
||||
@@ -92,7 +92,7 @@ var _ = ginkgo.Describe("[Feature: Group]", func() {
|
||||
loadBalancer.groupKey = "123"
|
||||
`, fooPort, remotePort, barPort, remotePort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
fooCount := 0
|
||||
barCount := 0
|
||||
@@ -157,7 +157,7 @@ var _ = ginkgo.Describe("[Feature: Group]", func() {
|
||||
loadBalancer.groupKey = "123"
|
||||
`, fooPort, barPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
fooCount := 0
|
||||
barCount := 0
|
||||
@@ -222,7 +222,7 @@ var _ = ginkgo.Describe("[Feature: Group]", func() {
|
||||
loadBalancer.groupKey = "123"
|
||||
`, fooPort, barPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
proxyURL := fmt.Sprintf("http://127.0.0.1:%d", vhostPort)
|
||||
fooCount := 0
|
||||
@@ -286,7 +286,7 @@ var _ = ginkgo.Describe("[Feature: Group]", func() {
|
||||
healthCheck.intervalSeconds = 1
|
||||
`, fooPort, remotePort, barPort, remotePort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
// check foo and bar is ok
|
||||
results := []string{}
|
||||
@@ -357,7 +357,7 @@ var _ = ginkgo.Describe("[Feature: Group]", func() {
|
||||
healthCheck.path = "/healthz"
|
||||
`, fooPort, barPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
// send first HTTP request
|
||||
var contents []string
|
||||
|
||||
@@ -37,7 +37,7 @@ var _ = ginkgo.Describe("[Feature: Heartbeat]", func() {
|
||||
`, serverPort, f.PortByName(framework.TCPEchoServerPort), remotePort)
|
||||
|
||||
// run frps and frpc
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Protocol("tcp").Port(remotePort).Ensure()
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ var _ = ginkgo.Describe("[Feature: Monitor]", func() {
|
||||
remotePort = %d
|
||||
`, framework.TCPEchoServerPort, remotePort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(remotePort).Ensure()
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
@@ -48,7 +48,7 @@ var _ = ginkgo.Describe("[Feature: Real IP]", func() {
|
||||
customDomains = ["normal.example.com"]
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
@@ -82,7 +82,7 @@ var _ = ginkgo.Describe("[Feature: Real IP]", func() {
|
||||
customDomains = ["normal.example.com"]
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
@@ -112,7 +112,7 @@ var _ = ginkgo.Describe("[Feature: Real IP]", func() {
|
||||
localAddr = "127.0.0.1:%d"
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
tlsConfig, err := transport.NewServerTLSConfig("", "", "")
|
||||
framework.ExpectNoError(err)
|
||||
@@ -154,7 +154,7 @@ var _ = ginkgo.Describe("[Feature: Real IP]", func() {
|
||||
localAddr = "127.0.0.1:%d"
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
localServer := httpserver.New(
|
||||
httpserver.WithBindPort(localPort),
|
||||
@@ -212,7 +212,7 @@ var _ = ginkgo.Describe("[Feature: Real IP]", func() {
|
||||
transport.proxyProtocolVersion = "v2"
|
||||
`, localPort, remotePort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(remotePort).Ensure(func(resp *request.Response) bool {
|
||||
log.Tracef("proxy protocol get SourceAddr: %s", string(resp.Content))
|
||||
@@ -262,7 +262,7 @@ var _ = ginkgo.Describe("[Feature: Real IP]", func() {
|
||||
transport.proxyProtocolVersion = "v2"
|
||||
`, localPort, remotePort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Protocol("udp").Port(remotePort).Ensure(func(resp *request.Response) bool {
|
||||
log.Tracef("udp proxy protocol get SourceAddr: %s", string(resp.Content))
|
||||
@@ -309,7 +309,7 @@ var _ = ginkgo.Describe("[Feature: Real IP]", func() {
|
||||
transport.proxyProtocolVersion = "v2"
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com")
|
||||
|
||||
@@ -3,6 +3,8 @@ package features
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
@@ -25,7 +27,8 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
|
||||
sshTunnelGateway.bindPort = %d
|
||||
`, sshPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, nil)
|
||||
f.RunProcesses(serverConf, nil)
|
||||
framework.ExpectNoError(framework.WaitForTCPReady(net.JoinHostPort("127.0.0.1", strconv.Itoa(sshPort)), 5*time.Second))
|
||||
|
||||
localPort := f.PortByName(framework.TCPEchoServerPort)
|
||||
remotePort := f.AllocPort()
|
||||
@@ -49,7 +52,8 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
|
||||
sshTunnelGateway.bindPort = %d
|
||||
`, vhostPort, sshPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, nil)
|
||||
f.RunProcesses(serverConf, nil)
|
||||
framework.ExpectNoError(framework.WaitForTCPReady(net.JoinHostPort("127.0.0.1", strconv.Itoa(sshPort)), 5*time.Second))
|
||||
|
||||
localPort := f.PortByName(framework.HTTPSimpleServerPort)
|
||||
tc := ssh.NewTunnelClient(
|
||||
@@ -76,7 +80,8 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
|
||||
sshTunnelGateway.bindPort = %d
|
||||
`, vhostPort, sshPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, nil)
|
||||
f.RunProcesses(serverConf, nil)
|
||||
framework.ExpectNoError(framework.WaitForTCPReady(net.JoinHostPort("127.0.0.1", strconv.Itoa(sshPort)), 5*time.Second))
|
||||
|
||||
localPort := f.AllocPort()
|
||||
testDomain := "test.example.com"
|
||||
@@ -118,7 +123,8 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
|
||||
sshTunnelGateway.bindPort = %d
|
||||
`, tcpmuxPort, sshPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, nil)
|
||||
f.RunProcesses(serverConf, nil)
|
||||
framework.ExpectNoError(framework.WaitForTCPReady(net.JoinHostPort("127.0.0.1", strconv.Itoa(sshPort)), 5*time.Second))
|
||||
|
||||
localPort := f.AllocPort()
|
||||
testDomain := "test.example.com"
|
||||
@@ -173,7 +179,8 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
|
||||
bindPort = %d
|
||||
`, bindPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{visitorConf})
|
||||
f.RunProcesses(serverConf, []string{visitorConf})
|
||||
framework.ExpectNoError(framework.WaitForTCPReady(net.JoinHostPort("127.0.0.1", strconv.Itoa(sshPort)), 5*time.Second))
|
||||
|
||||
localPort := f.PortByName(framework.TCPEchoServerPort)
|
||||
tc := ssh.NewTunnelClient(
|
||||
|
||||
@@ -30,7 +30,7 @@ var _ = ginkgo.Describe("[Feature: Store]", func() {
|
||||
path = "%s/store.json"
|
||||
`, adminPort, f.TempDirectory)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
proxyConfig := map[string]any{
|
||||
@@ -71,7 +71,7 @@ var _ = ginkgo.Describe("[Feature: Store]", func() {
|
||||
path = "%s/store.json"
|
||||
`, adminPort, f.TempDirectory)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
proxyConfig := map[string]any{
|
||||
@@ -125,7 +125,7 @@ var _ = ginkgo.Describe("[Feature: Store]", func() {
|
||||
path = "%s/store.json"
|
||||
`, adminPort, f.TempDirectory)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
proxyConfig := map[string]any{
|
||||
@@ -173,7 +173,7 @@ var _ = ginkgo.Describe("[Feature: Store]", func() {
|
||||
path = "%s/store.json"
|
||||
`, adminPort, f.TempDirectory)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
proxyConfig := map[string]any{
|
||||
@@ -225,7 +225,7 @@ var _ = ginkgo.Describe("[Feature: Store]", func() {
|
||||
webServer.port = %d
|
||||
`, adminPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
@@ -247,7 +247,7 @@ var _ = ginkgo.Describe("[Feature: Store]", func() {
|
||||
path = "%s/store.json"
|
||||
`, adminPort, f.TempDirectory)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
invalidBody, _ := json.Marshal(map[string]any{
|
||||
@@ -280,7 +280,7 @@ var _ = ginkgo.Describe("[Feature: Store]", func() {
|
||||
path = "%s/store.json"
|
||||
`, adminPort, f.TempDirectory)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
createBody, _ := json.Marshal(map[string]any{
|
||||
|
||||
Reference in New Issue
Block a user