Skip to content

Commit

Permalink
test: avoid being conflict with well-known ports
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Oct 22, 2024
1 parent 4e25755 commit ce19cf2
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ jobs:
plugins-integration-test:
timeout-minutes: 10
runs-on: ubuntu-latest
env:
# to test the custom port feature
TEST_ENVOY_ADMIN_API_PORT: 9901
TEST_ENVOY_CONTROL_PLANE_PORT: 9902
TEST_ENVOY_DATA_PLANE_PORT: 9903
defaults:
run:
working-directory: ./plugins
Expand Down
13 changes: 12 additions & 1 deletion api/plugins/tests/integration/controlplane/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ func (cp *ControlPlane) Start() {
// only use it on Linux.
}

lis, _ := net.Listen("tcp", host+":9999")
port := ":9999"
portEnv := os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")
if portEnv != "" {
port = ":" + portEnv
}

lis, err := net.Listen("tcp", host+port)
if err != nil {
logger.Error(err, "failed to listen")
return
}

if err := cp.grpcServer.Serve(lis); err != nil {
logger.Error(err, "failed to start control plane")
}
Expand Down
14 changes: 14 additions & 0 deletions api/plugins/tests/integration/dataplane/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) {

staticResources := root["static_resources"].(map[string]interface{})
clusters := staticResources["clusters"].([]interface{})

port := "9999"
portEnv := os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")
if portEnv != "" {
port = portEnv
}
for _, c := range clusters {
if c.(map[string]interface{})["name"] == "config_server" {
load := c.(map[string]interface{})["load_assignment"].(map[string]interface{})["endpoints"].([]interface{})[0].(map[string]interface{})["lb_endpoints"].([]interface{})[0].(map[string]interface{})["endpoint"].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{})
load["port_value"] = port
break
}
}

newClusters := []interface{}{}
for _, c := range b.clusters {
newClusters = append(newClusters, c)
Expand Down
15 changes: 14 additions & 1 deletion api/plugins/tests/integration/dataplane/data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
return nil, err
}

adminAPIPort := "9998"
adminAPIPortEnv := os.Getenv("TEST_ENVOY_ADMIN_API_PORT")
if adminAPIPortEnv != "" {
adminAPIPort = adminAPIPortEnv
}

dataPlanePort := "10000"
dataPlanePortEnv := os.Getenv("TEST_ENVOY_DATA_PLANE_PORT")
if dataPlanePortEnv != "" {
dataPlanePort = dataPlanePortEnv
}

cmdline := "docker run" +
" --name " + containerName +
" --network " + networkName +
Expand All @@ -199,7 +211,8 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
" -v /tmp:/tmp" +
" -e GOCOVERDIR=" + coverDir +
" " + strings.Join(envs, " ") +
" -p 10000:10000 -p 9998:9998 " + hostAddr + " " +
" -p " + dataPlanePort + ":10000 -p " + adminAPIPort + ":9998 " +
hostAddr + " " +
image

content, _ := os.ReadFile(cfgFile.Name())
Expand Down
2 changes: 1 addition & 1 deletion api/tests/integration/filtermanager_latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestFilterManagerTrailersWithGrpcBackend(t *testing.T) {
}
defer dp.Stop()

helper.WaitServiceUp(t, ":50051", "grpc")
helper.WaitServiceUp(t, ":50001", "grpc")

s := &filtermanager.FilterManagerConfig{
Plugins: []*model.FilterConfig{
Expand Down
2 changes: 1 addition & 1 deletion api/tests/integration/testdata/grpc_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ load_assignment:
address:
socket_address:
address: grpc
port_value: 50051
port_value: 50001
2 changes: 1 addition & 1 deletion api/tests/integration/testdata/services/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
grpc:
build: ./grpc
ports:
- "50051:50051"
- "50001:50051"
restart: unless-stopped
networks:
service:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ You may have noticed that when executing `go test`, we added `-tags envoy1.29`.

## Port usage

The test framework will use:
The test framework will occupy the following ports on the host machine:

* `:2023` to represent invalid port
* `:9999` for the control plane
* `:10000` for the Envoy proxy
* `:10001` for the backend server and mock external server
* `:9998` for the Envoy's Admin API, which can be modified by the environment variable `TEST_ENVOY_ADMIN_API_PORT`
* `:9999` for the control plane, which can be modified by the environment variable `TEST_ENVOY_CONTROL_PLANE_PORT`
* `:10000` for the Envoy proxy, which can be modified by the environment variable `TEST_ENVOY_DATA_PLANE_PORT`

For example, `TEST_ENVOY_CONTROL_PLANE_PORT=19999 go test -v ./tests/integration -run TestPluginXX` will use `:19999` as the control plane port.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ title: 插件集成测试框架

## 端口使用

测试框架将使用
测试框架将占用 host 上的下述端口

* `:2023` 用于表示错误的端口
* `:9999` 用于控制平面
* `:10000` 用于数据面
* `:10001` 用于后端服务器和模拟外部服务器
* `:9998` 用于 Envoy 管理 API,可通过环境变量 `TEST_ENVOY_ADMIN_API_PORT` 修改
* `:9999` 用于控制平面,可通过环境变量 `TEST_ENVOY_CONTROL_PLANE_PORT` 修改
* `:10000` 用于数据面,可通过环境变量 `TEST_ENVOY_DATA_PLANE_PORT` 修改

例如,`TEST_ENVOY_CONTROL_PLANE_PORT=19999 go test -v ./tests/integration -run TestPluginXX` 将使用 `:19999` 端口作为控制平面端口。

0 comments on commit ce19cf2

Please sign in to comment.