mirror of
https://github.com/fatedier/frp.git
synced 2026-03-12 12:59:24 +08:00
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.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package features
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/onsi/ginkgo/v2"
|
|
|
|
"github.com/fatedier/frp/pkg/util/log"
|
|
"github.com/fatedier/frp/test/e2e/framework"
|
|
"github.com/fatedier/frp/test/e2e/framework/consts"
|
|
"github.com/fatedier/frp/test/e2e/pkg/request"
|
|
)
|
|
|
|
var _ = ginkgo.Describe("[Feature: Monitor]", func() {
|
|
f := framework.NewDefaultFramework()
|
|
|
|
ginkgo.It("Prometheus metrics", func() {
|
|
dashboardPort := f.AllocPort()
|
|
serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
|
|
enablePrometheus = true
|
|
webServer.addr = "0.0.0.0"
|
|
webServer.port = %d
|
|
`, dashboardPort)
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
remotePort := f.AllocPort()
|
|
clientConf += fmt.Sprintf(`
|
|
[[proxies]]
|
|
name = "tcp"
|
|
type = "tcp"
|
|
localPort = {{ .%s }}
|
|
remotePort = %d
|
|
`, framework.TCPEchoServerPort, remotePort)
|
|
|
|
f.RunProcesses(serverConf, []string{clientConf})
|
|
|
|
framework.NewRequestExpect(f).Port(remotePort).Ensure()
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
|
r.HTTP().Port(dashboardPort).HTTPPath("/metrics")
|
|
}).Ensure(func(resp *request.Response) bool {
|
|
log.Tracef("prometheus metrics response: \n%s", resp.Content)
|
|
if resp.Code != 200 {
|
|
return false
|
|
}
|
|
if !strings.Contains(string(resp.Content), "traffic_in") {
|
|
return false
|
|
}
|
|
return true
|
|
})
|
|
})
|
|
})
|