-
Notifications
You must be signed in to change notification settings - Fork 6.2k
tests: add external starter mode realtikv harness #68463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChangRui-Ryan
wants to merge
2
commits into
pingcap:master
Choose a base branch
from
ChangRui-Ryan:changrui_cse_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
tests/realtikvtest/scripts/next-gen/run-starter-tests-with-server.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #! /usr/bin/env bash | ||
| # | ||
| # Copyright 2026 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. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| starter_data_dir="" | ||
| starter_tidb_pid="" | ||
|
|
||
| function find_available_port() { | ||
| local port="$1" | ||
| while [[ "${port}" -lt 65536 ]]; do | ||
| if ! lsof -nP -iTCP:"${port}" -sTCP:LISTEN >/dev/null 2>&1; then | ||
| echo "${port}" | ||
| return 0 | ||
| fi | ||
| port=$((port + 1)) | ||
| done | ||
| echo "no available port found from $1" >&2 | ||
| return 1 | ||
| } | ||
|
|
||
| function cleanup_tidb_server() { | ||
| if [[ -n "${starter_tidb_pid:-}" ]]; then | ||
| if kill -0 "${starter_tidb_pid}" >/dev/null 2>&1; then | ||
| kill -TERM "${starter_tidb_pid}" >/dev/null 2>&1 || true | ||
| fi | ||
| wait "${starter_tidb_pid}" >/dev/null 2>&1 || true | ||
| starter_tidb_pid="" | ||
| fi | ||
| if [[ -n "${starter_data_dir:-}" && -d "${starter_data_dir}" ]]; then | ||
| rm -rf -- "${starter_data_dir}" | ||
| starter_data_dir="" | ||
| fi | ||
| } | ||
|
|
||
| function wait_for_tidb_server() { | ||
| local status_url="$1" | ||
| local tidb_pid="$2" | ||
| local log_file="$3" | ||
| local stdout_log_file="$4" | ||
|
|
||
| for _ in {1..60}; do | ||
| if curl -sf "${status_url}/status" >/dev/null 2>&1; then | ||
| return 0 | ||
| fi | ||
| if ! kill -0 "${tidb_pid}" >/dev/null 2>&1; then | ||
| echo "tidb-server exited before becoming ready. Log tail:" >&2 | ||
| tail -200 "${log_file}" >&2 || true | ||
| tail -200 "${stdout_log_file}" >&2 || true | ||
| return 1 | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| echo "timed out waiting for tidb-server. Log tail:" >&2 | ||
| tail -200 "${log_file}" >&2 || true | ||
| tail -200 "${stdout_log_file}" >&2 || true | ||
| return 1 | ||
| } | ||
|
|
||
| function run_under_cluster() { | ||
| local test_suite="${1:-startertest}" | ||
| local suite_timeout="${2:-40m}" | ||
| shift || true | ||
| shift || true | ||
| local extra_go_test_args=("$@") | ||
|
|
||
| local self_dir | ||
| self_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" | ||
| local repo_root | ||
| repo_root="$(realpath "${self_dir}/../../../..")" | ||
| cd "${repo_root}" | ||
|
|
||
| local tidb_server_bin="${TIDB_SERVER_BIN:-bin/tidb-server}" | ||
| if [[ ! -x "${tidb_server_bin}" ]]; then | ||
| echo "tidb-server binary '${tidb_server_bin}' does not exist or is not executable." >&2 | ||
| echo "Build a next-gen TiDB server first, for example: NEXT_GEN=1 make server" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| local max_allowed_packet="${STARTER_MAX_ALLOWED_PACKET:-8192}" | ||
| starter_data_dir="$(mktemp -d)" | ||
| local config_file="${starter_data_dir}/starter.toml" | ||
| local log_file="${starter_data_dir}/tidb.log" | ||
| local stdout_log_file="${starter_data_dir}/tidb-stdout.log" | ||
| local tidb_port | ||
| tidb_port="$(find_available_port "${STARTER_TIDB_PORT:-4000}")" | ||
| local status_port | ||
| status_port="$(find_available_port "${STARTER_TIDB_STATUS_PORT:-10080}")" | ||
| if [[ "${status_port}" == "${tidb_port}" ]]; then | ||
| status_port="$(find_available_port "$((status_port + 1))")" | ||
| fi | ||
| local pd_endpoints="${STARTER_PD_ENDPOINTS:-127.0.0.1:2379,127.0.0.1:2382,127.0.0.1:2384}" | ||
| local tikv_worker_url="${STARTER_TIKV_WORKER_URL:-localhost:19000}" | ||
|
|
||
| cat > "${config_file}" <<EOF | ||
| deploy-mode = "starter" | ||
| max-allowed-packet = ${max_allowed_packet} | ||
| tikv-worker-url = "${tikv_worker_url}" | ||
| EOF | ||
|
|
||
| echo "Starting external starter tidb-server on port ${tidb_port}, status port ${status_port}, log file ${log_file}" | ||
| "${tidb_server_bin}" \ | ||
| -P "${tidb_port}" \ | ||
| -status "${status_port}" \ | ||
| -host "127.0.0.1" \ | ||
| -advertise-address "127.0.0.1" \ | ||
| -status-host "127.0.0.1" \ | ||
| -store tikv \ | ||
| -path "${pd_endpoints}" \ | ||
| -config "${config_file}" \ | ||
| -keyspace-name SYSTEM \ | ||
| -tidb-service-scope dxf_service \ | ||
| -log-file "${log_file}" > "${stdout_log_file}" 2>&1 & | ||
| starter_tidb_pid="$!" | ||
| trap cleanup_tidb_server EXIT | ||
|
|
||
| local status_url="http://127.0.0.1:${status_port}" | ||
| wait_for_tidb_server "${status_url}" "${starter_tidb_pid}" "${log_file}" "${stdout_log_file}" | ||
|
|
||
| export TIDB_STARTER_TEST_DSN="root@tcp(127.0.0.1:${tidb_port})/?timeout=5s&readTimeout=30s&writeTimeout=30s&multiStatements=true" | ||
| export TIDB_STARTER_STATUS_URL="${status_url}" | ||
| export TIDB_STARTER_MAX_ALLOWED_PACKET="${max_allowed_packet}" | ||
| export TIDB_STARTER_TIKV_WORKER_URL="${tikv_worker_url}" | ||
|
|
||
| echo "Running external starter tests: ./tests/realtikvtest/${test_suite}" | ||
| NEXT_GEN=1 go test "./tests/realtikvtest/${test_suite}" -v --tags=intest,nextgen -timeout "${suite_timeout}" "${extra_go_test_args[@]}" | ||
| } | ||
|
|
||
| function main() { | ||
| local self_dir | ||
| self_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" | ||
| local repo_root | ||
| repo_root="$(realpath "${self_dir}/../../../..")" | ||
| cd "${repo_root}" | ||
|
|
||
| "${self_dir}/bootstrap-test-with-cluster.sh" "${self_dir}/run-starter-tests-with-server.sh" --under-cluster "$@" | ||
| } | ||
|
|
||
| if [[ "${1:-}" == "--under-cluster" ]]; then | ||
| shift | ||
| run_under_cluster "$@" | ||
| else | ||
| main "$@" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| load("@io_bazel_rules_go//go:def.bzl", "go_test") | ||
|
|
||
| go_test( | ||
| name = "startertest_test", | ||
| timeout = "moderate", | ||
| srcs = ["starter_external_test.go"], | ||
| flaky = True, | ||
| shard_count = 4, | ||
| deps = [ | ||
| "@com_github_go_sql_driver_mysql//:mysql", | ||
| "@com_github_stretchr_testify//require", | ||
| ], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.