Skip to content

Commit 606838a

Browse files
committed
Switch TiDB tests to TiUP Playground with pre-installation
Replace slow Docker-based TiDB cluster setup with TiUP Playground. - Pre-install TiUP and TiDB versions in prepare-dependencies job - Cache TiUP components for reuse across test jobs - Use new tidb-playground.sh script for faster cluster startup - Expected to reduce TiDB test time from 5-10+ minutes to 2-3 minutes per test
1 parent 81b6ced commit 606838a

File tree

3 files changed

+140
-5
lines changed

3 files changed

+140
-5
lines changed

.github/workflows/main.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,43 @@ jobs:
4444
- name: Vendor Go dependencies
4545
run: go mod vendor
4646

47+
- name: Cache TiUP components
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
~/.tiup
52+
key: ${{ runner.os }}-tiup-${{ hashFiles('**/.github/workflows/main.yml') }}
53+
restore-keys: |
54+
${{ runner.os }}-tiup-
55+
56+
- name: Install TiUP
57+
run: |
58+
if ! command -v tiup &> /dev/null; then
59+
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
60+
fi
61+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
62+
63+
- name: Pre-download TiDB versions
64+
run: |
65+
export PATH=$HOME/.tiup/bin:$PATH
66+
# Pre-download TiDB versions used in tests (only if not already cached)
67+
tiup install tidb:v6.1.0 || true
68+
tiup install tidb:v6.5.3 || true
69+
tiup install tidb:v7.1.5 || true
70+
tiup install tidb:v7.5.2 || true
71+
tiup install tidb:v8.1.0 || true
72+
# Also install PD and TiKV components
73+
tiup install pd:v6.1.0 || true
74+
tiup install pd:v6.5.3 || true
75+
tiup install pd:v7.1.5 || true
76+
tiup install pd:v7.5.2 || true
77+
tiup install pd:v8.1.0 || true
78+
tiup install tikv:v6.1.0 || true
79+
tiup install tikv:v6.5.3 || true
80+
tiup install tikv:v7.1.5 || true
81+
tiup install tikv:v7.5.2 || true
82+
tiup install tikv:v8.1.0 || true
83+
4784
- name: Upload Terraform binary
4885
uses: actions/upload-artifact@v4
4986
with:
@@ -120,6 +157,26 @@ jobs:
120157
sudo apt-get update -qq
121158
sudo apt-get install -y --no-install-recommends mysql-client
122159
160+
- name: Cache TiUP components
161+
if: contains(matrix.target, 'tidb')
162+
uses: actions/cache@v4
163+
with:
164+
path: |
165+
~/.tiup
166+
key: ${{ runner.os }}-tiup-${{ hashFiles('**/.github/workflows/main.yml') }}
167+
restore-keys: |
168+
${{ runner.os }}-tiup-
169+
170+
- name: Install TiUP (if not cached)
171+
if: contains(matrix.target, 'tidb')
172+
run: |
173+
if ! command -v tiup &> /dev/null; then
174+
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
175+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
176+
else
177+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
178+
fi
179+
123180
- name: Run tests {{ matrix.target }}
124181
env:
125182
GOFLAGS: -mod=vendor

GNUmakefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ testtidb%:
8787
# WARNING: this does not work as a bare task run, it only instantiates correctly inside the versioned TiDB task run
8888
# otherwise MYSQL_PORT and version are unset.
8989
testtidb:
90-
@sh -c "'$(CURDIR)/scripts/tidb-test-cluster.sh' --init --port $(MYSQL_PORT) --version $(MYSQL_VERSION)"
91-
@echo 'Waiting for TiDB...'
92-
@while ! mysql -h 127.0.0.1 -P $(MYSQL_PORT) -u "$(TEST_USER)" -e 'SELECT 1' >/dev/null 2>&1; do printf '.'; sleep 1; done ; echo ; echo "Connected!"
93-
MYSQL_USERNAME="$(TEST_USER)" MYSQL_PASSWORD="" MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT) $(MAKE) testacc
94-
@sh -c "'$(CURDIR)/scripts/tidb-test-cluster.sh' --destroy"
90+
@MYSQL_VERSION=$(MYSQL_VERSION) MYSQL_PORT=$(MYSQL_PORT) $(CURDIR)/scripts/tidb-playground.sh start || exit 1
91+
MYSQL_USERNAME="$(TEST_USER)" MYSQL_PASSWORD="" MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT) $(MAKE) testacc; \
92+
TEST_RESULT=$$?; \
93+
MYSQL_VERSION=$(MYSQL_VERSION) MYSQL_PORT=$(MYSQL_PORT) $(CURDIR)/scripts/tidb-playground.sh stop; \
94+
exit $$TEST_RESULT
9595

9696
testmariadb%:
9797
$(MAKE) MYSQL_VERSION=$* MYSQL_PORT=6$(shell echo "$*" | tr -d '.') testmariadb

scripts/tidb-playground.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
3+
# TiDB Playground wrapper script for testing
4+
# Uses TiUP playground for faster TiDB cluster startup
5+
6+
set -e
7+
8+
VERSION=${MYSQL_VERSION:-7.5.2}
9+
PORT=${MYSQL_PORT:-4000}
10+
MODE=${1:-start} # start or stop
11+
12+
# Ensure TiUP is in PATH
13+
export PATH=$HOME/.tiup/bin:$PATH
14+
15+
if ! command -v tiup &> /dev/null; then
16+
echo "TiUP not found. Installing..."
17+
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
18+
export PATH=$HOME/.tiup/bin:$PATH
19+
fi
20+
21+
if [ "$MODE" = "start" ]; then
22+
echo "==> Starting TiDB Playground v${VERSION} on port ${PORT}..."
23+
24+
# Clean up any existing playground instances
25+
pkill -f "tiup playground" || true
26+
sleep 1
27+
28+
# Start playground in background
29+
tiup playground ${VERSION} \
30+
--db 1 \
31+
--kv 1 \
32+
--pd 1 \
33+
--tiflash 0 \
34+
--without-monitor \
35+
--host 0.0.0.0 \
36+
--port ${PORT} \
37+
> /tmp/tidb-playground-${PORT}.log 2>&1 &
38+
39+
PLAYGROUND_PID=$!
40+
echo $PLAYGROUND_PID > /tmp/tidb-playground-${PORT}.pid
41+
42+
# Wait for TiDB to be ready (max 120 seconds)
43+
echo "Waiting for TiDB to be ready..."
44+
for i in {1..120}; do
45+
if mysql -h 127.0.0.1 -P ${PORT} -u root -e 'SELECT 1' >/dev/null 2>&1; then
46+
echo "TiDB is ready!"
47+
exit 0
48+
fi
49+
sleep 1
50+
if [ $((i % 10)) -eq 0 ]; then
51+
printf "."
52+
fi
53+
done
54+
55+
echo ""
56+
echo "ERROR: TiDB failed to start within 120 seconds"
57+
echo "Last 20 lines of playground log:"
58+
tail -20 /tmp/tidb-playground-${PORT}.log || true
59+
exit 1
60+
61+
elif [ "$MODE" = "stop" ]; then
62+
echo "==> Stopping TiDB Playground..."
63+
64+
# Kill by PID if available
65+
if [ -f /tmp/tidb-playground-${PORT}.pid ]; then
66+
PID=$(cat /tmp/tidb-playground-${PORT}.pid)
67+
kill $PID 2>/dev/null || true
68+
rm /tmp/tidb-playground-${PORT}.pid
69+
fi
70+
71+
# Kill any remaining tiup playground processes
72+
pkill -f "tiup playground" || true
73+
74+
# Clean up log file
75+
rm -f /tmp/tidb-playground-${PORT}.log
76+
77+
echo "TiDB Playground stopped"
78+
fi

0 commit comments

Comments
 (0)