docs/agents/testing-flow.md
This document provides command playbooks for test execution.
Root AGENTS.md is the source of truth for policy-level requirements; this file is operational guidance.
Use AGENTS.md -> Task -> Validation Matrix first, run the smallest valid command set, and report exact commands.
Detailed command snippets in this file are the canonical operational reference; skills under .agents/skills/ should point here rather than duplicating long command blocks.
/pkg/...)pushd pkg/<package_name>
go test -run <TestName> -tags=intest,deadlock
popd
-run <TestName>); use package-wide runs only when needed.-record only for test suites that explicitly support it.AGENTS.md -> Quick Decision Matrix (Unit tests in a package that uses failpoints).rg -n --fixed-strings -- "failpoint." pkg/<package_name>
rg -n --fixed-strings -- "testfailpoint." pkg/<package_name>
# If BUILD.bazel exists, also check failpoint dependency.
test -f pkg/<package_name>/BUILD.bazel && rg -n --fixed-strings -- "@com_github_pingcap_failpoint//:failpoint" pkg/<package_name>/BUILD.bazel
rg finds matches, run with failpoints enabled.rg finds no matches, run without failpoint enable/disable and state the check evidence in the final report.-tags=intest,deadlock does not enable failpoints../tools/check/failpoint-go-test.sh pkg/<package_name> -run <TestName>
go test, and always disables failpoints during cleanup.go test flags after the package path, for example ./tools/check/failpoint-go-test.sh pkg/<package_name> -run <TestName> -count=1.-tags is omitted, the script defaults to -tags=intest,deadlock.-tags=intest,deadlock,nextgen when a test run also needs nextgen.bazel test), run make bazel-failpoint-enable first, then make bazel-failpoint-disable after tests.make bazel_test, do not run make bazel-failpoint-enable separately because bazel_test already depends on it; still run make bazel-failpoint-disable after tests.AGENTS.md -> Quick Decision Matrix (Bug fix).shard_count, and package-specific testdata rules live in .agents/skills/tidb-test-guidelines.Tests when preparing a PR update./tests/integrationtest)tests/integrationtest/t.tests/integrationtest/r.pushd tests/integrationtest
./run-tests.sh -r <TestName>
popd
tests/integrationtest/r and confirm each diff matches expected behavior.t/planner/core/binary_plan.test, then TestName is planner/core/binary_plan./tests/realtikvtest)tests/realtikvtest/.AGENTS.md -> Quick Decision Matrix (RealTiKV tests).Start playground in background:
tiup playground --mode tikv-slim --tag realtikvtest &
PLAYGROUND_PID=$!
Default PD is 127.0.0.1:2379; if it is unavailable, use a non-default port or port offset.
Using --tag realtikvtest keeps data under ${HOME}/.tiup/data/realtikvtest after exit; remove it during cleanup.
tiup playground --mode tikv-slim --tag realtikvtest --pd.port 12379 &
PLAYGROUND_PID=$!
# or
tiup playground --mode tikv-slim --tag realtikvtest --port-offset 10000 &
PLAYGROUND_PID=$!
PD_ADDR=127.0.0.1:2379
# If started with `--pd.port 12379` or `--port-offset 10000`, use:
# PD_ADDR=127.0.0.1:12379
curl -f "http://${PD_ADDR}/pd/api/v1/version"
until curl -sf "http://${PD_ADDR}/pd/api/v1/version" >/dev/null; do sleep 1; done
go test -run <TestName> -tags=intest,deadlock ./tests/realtikvtest/<dir>/...
# non-default PD example
go test -run <TestName> -tags=intest,deadlock ./tests/realtikvtest/<dir>/... -args \
-tikv-path "tikv://127.0.0.1:12379?disableGC=true"
-v by default; add it only for debugging.[ -n "${PLAYGROUND_PID:-}" ] && kill "${PLAYGROUND_PID}" 2>/dev/null || true
[ -n "${PLAYGROUND_PID:-}" ] && wait "${PLAYGROUND_PID}" 2>/dev/null || true
rm -rf "${HOME}/.tiup/data/realtikvtest"
# Cleanup check: PD endpoint should be unreachable after teardown.
! curl -sf "http://${PD_ADDR}/pd/api/v1/version"
Cleanup-safe template (recommended for long local debug runs):
PD_ADDR=127.0.0.1:2379
(
cleanup() {
[ -n "${PLAYGROUND_PID:-}" ] && kill "${PLAYGROUND_PID}" 2>/dev/null || true
[ -n "${PLAYGROUND_PID:-}" ] && wait "${PLAYGROUND_PID}" 2>/dev/null || true
rm -rf "${HOME}/.tiup/data/realtikvtest"
}
trap cleanup EXIT INT TERM
tiup playground --mode tikv-slim --tag realtikvtest &
PLAYGROUND_PID=$!
until curl -sf "http://${PD_ADDR}/pd/api/v1/version" >/dev/null; do sleep 1; done
go test -run <TestName> -tags=intest,deadlock ./tests/realtikvtest/<dir>/...
)
! curl -sf "http://${PD_ADDR}/pd/api/v1/version"
Quick Decision Matrix and skip costly realtikvtest.tests/realtikvtest/scripts/classic/ and tests/realtikvtest/scripts/next-gen/.