*: remove portgenerator to cleanup codes (#56465)

This commit is contained in:
bb7133
2024-10-07 21:41:16 -07:00
committed by GitHub
parent f7f573b6e1
commit 9d2227d5ca
4 changed files with 36 additions and 100 deletions

1
.gitignore vendored
View File

@ -11,7 +11,6 @@ profile.coverprofile
mysql_tester
tests/integrationtest/integration-test.out
tests/integrationtest/integrationtest_tidb-server
tests/integrationtest/portgenerator
tests/integrationtest/s/
tests/integrationtest/replayer/
*.fail.go

View File

@ -1,19 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "portgenerator_lib",
srcs = ["portgenerator.go"],
importpath = "github.com/pingcap/tidb/cmd/portgenerator",
visibility = ["//visibility:private"],
deps = [
"@com_github_phayes_freeport//:freeport",
"@com_github_pingcap_log//:log",
"@org_uber_go_zap//:zap",
],
)
go_binary(
name = "portgenerator",
embed = [":portgenerator_lib"],
visibility = ["//visibility:public"],
)

View File

@ -1,50 +0,0 @@
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"fmt"
"github.com/phayes/freeport"
"github.com/pingcap/log"
"go.uber.org/zap"
)
var (
count uint
)
func init() {
flag.UintVar(&count, "count", 1, "number of generated ports")
}
func generatePorts(count int) []int {
var (
err error
ports []int
)
if ports, err = freeport.GetFreePorts(count); err != nil {
log.Fatal("no more free ports", zap.Error(err))
}
return ports
}
func main() {
flag.Parse()
for _, port := range generatePorts(int(count)) {
fmt.Println(port)
}
}

View File

@ -58,19 +58,45 @@ function help_message()
This option will be ignored if \"-r <test-name>\" is provided.
Run all tests if this option is not provided.
-p <portgenerator-path>: Use port generator in <portgenerator-path> for generating port numbers.
"
}
function build_portgenerator()
{
portgenerator="./portgenerator"
echo "building portgenerator binary: $portgenerator"
rm -rf $portgenerator
GO111MODULE=on go build -o $portgenerator github.com/pingcap/tidb/cmd/portgenerator
# Function to find an available port starting from a given port
function find_available_port() {
local port=$1
while :; do
if [ "$port" -ge 65536 ]; then
echo "Error: No available ports found below 65536." >&2
exit 1
fi
if ! lsof -i :"$port" &> /dev/null; then
echo $port
return 0
fi
((port++))
done
}
# Function to find multiple available ports starting from a given port
function find_multiple_available_ports() {
local start_port=$1
local count=$2
local ports=()
while [ ${#ports[@]} -lt $count ]; do
local available_port=$(find_available_port $start_port)
if [ $? -eq 0 ]; then
ports+=($available_port)
((start_port = available_port + 1))
else
echo "Error: Could not find an available port." >&2
exit 1
fi
done
echo "${ports[@]}"
}
function build_tidb_server()
{
@ -99,7 +125,7 @@ function extract_stats()
unzip -qq s.zip
}
while getopts "t:s:r:b:d:c:i:h:p" opt; do
while getopts "t:s:r:b:d:c:i:h" opt; do
case $opt in
t)
tests="$OPTARG"
@ -146,9 +172,6 @@ while getopts "t:s:r:b:d:c:i:h:p" opt; do
help_message
exit 0
;;
p)
portgenerator="$OPTARG"
;;
*)
help_message 1>&2
exit 1
@ -164,11 +187,6 @@ if [ $build -eq 1 ]; then
else
echo "skip building tidb-server, using existing binary: $tidb_server"
fi
if [[ -z "$portgenerator" ]]; then
build_portgenerator
else
echo "skip building portgenerator, using existing binary: $portgenerator"
fi
build_mysql_tester
else
if [ -z "$tidb_server" ]; then
@ -187,23 +205,11 @@ else
echo "skip building mysql-tester, using existing binary: $mysql_tester"
fi
fi
if [ -z "$portgenerator" ]; then
portgenerator="./portgenerator"
if [[ ! -f "$portgenerator" ]]; then
build_portgenerator
else
echo "skip building portgenerator, using existing binary: $portgenerator"
fi
fi
fi
rm -rf $mysql_tester_log
ports=()
for port in $($portgenerator -count 2); do
ports+=("$port")
done
ports=($(find_multiple_available_ports 4000 2))
port=${ports[0]}
status=${ports[1]}