Skip to content

Commit 7d9b317

Browse files
committed
Add fast Unistore-based smoke tests for TiDB
Add a new fast test suite using TiDB's Unistore backend for quick smoke tests. Unistore is an in-memory storage backend that starts much faster than TiKV-based clusters. Changes: - Create tidb-playground-unistore.sh script for Unistore-based testing - Add testtidb-unistore* Makefile targets - Add tests-unistore job to CI workflow - Test latest of each major series: 6.5.12, 7.5.7, 8.5.3 Benefits: - Faster startup (~10-20s vs 30-60s for TiKV) - Single node setup (no TiKV coordination needed) - Quick feedback on basic compatibility issues - Runs in parallel with comprehensive TiKV tests The Unistore tests provide fast smoke testing while full TiKV tests ensure comprehensive coverage.
1 parent 8593df9 commit 7d9b317

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

.github/workflows/main.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,121 @@ jobs:
248248
env:
249249
GOFLAGS: -mod=vendor
250250
run: make ${{ matrix.target }}
251+
252+
# Fast Unistore-based smoke tests (latest of each major series)
253+
# These run quickly using Unistore backend for fast feedback
254+
tests-unistore:
255+
runs-on: ubuntu-22.04
256+
needs: [prepare-dependencies]
257+
strategy:
258+
fail-fast: false
259+
matrix:
260+
target:
261+
# Latest of each major series: 6.x, 7.x, 8.x
262+
- testtidb-unistore6.5.12
263+
- testtidb-unistore7.5.7
264+
- testtidb-unistore8.5.3
265+
steps:
266+
- name: Checkout Git repo
267+
uses: actions/checkout@v4
268+
with:
269+
fetch-depth: 1
270+
271+
- name: Set up Go
272+
uses: actions/setup-go@v4
273+
with:
274+
go-version-file: go.mod
275+
276+
- name: Download Terraform binary
277+
uses: actions/download-artifact@v4
278+
with:
279+
name: terraform-binary
280+
path: bin/
281+
282+
- name: Download vendor directory
283+
uses: actions/download-artifact@v4
284+
with:
285+
name: vendor-dir
286+
path: vendor/
287+
288+
- name: Make Terraform executable
289+
run: chmod +x bin/terraform
290+
291+
- name: Cache apt packages
292+
uses: actions/cache@v4
293+
with:
294+
path: /var/cache/apt
295+
key: ${{ runner.os }}-apt-${{ hashFiles('**/.github/workflows/main.yml') }}
296+
restore-keys: |
297+
${{ runner.os }}-apt-
298+
299+
- name: Install mysql client
300+
run: |
301+
sudo apt-get update -qq
302+
sudo apt-get install -y --no-install-recommends mysql-client
303+
304+
- name: Extract TiDB version from test target
305+
id: extract-tidb-version-unistore
306+
run: |
307+
# Extract version from testtidb-unistore6.5.12 -> 6.5.12
308+
VERSION=$(echo "${{ matrix.target }}" | sed 's/testtidb-unistore//')
309+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
310+
echo "TiDB version for Unistore smoke test: ${VERSION}"
311+
312+
- name: Cache TiUP binary (shared across all TiDB tests)
313+
id: cache-tiup-binary-unistore
314+
uses: actions/cache@v4
315+
with:
316+
path: |
317+
~/.tiup/bin
318+
~/.tiup/manifests
319+
# Cache TiUP binary separately (small, ~20MB) - shared by all TiDB tests
320+
key: ${{ runner.os }}-tiup-binary-${{ hashFiles('.github/workflows/main.yml') }}
321+
restore-keys: |
322+
${{ runner.os }}-tiup-binary-
323+
324+
- name: Cache TiDB components for this specific version
325+
id: cache-tidb-version-unistore
326+
uses: actions/cache@v4
327+
with:
328+
path: |
329+
~/.tiup/components
330+
# Cache components directory per version (~700-800MB per version)
331+
key: ${{ runner.os }}-tidb-${{ steps.extract-tidb-version-unistore.outputs.version }}-${{ hashFiles('.github/workflows/main.yml') }}
332+
restore-keys: |
333+
${{ runner.os }}-tidb-${{ steps.extract-tidb-version-unistore.outputs.version }}-
334+
335+
- name: Install TiUP (if not cached)
336+
run: |
337+
if ! command -v tiup &> /dev/null; then
338+
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
339+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
340+
else
341+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
342+
fi
343+
344+
- name: Update TiUP and playground component
345+
run: |
346+
export PATH=$HOME/.tiup/bin:$PATH
347+
tiup update --self || true
348+
tiup update playground || true
349+
350+
- name: Install TiDB components for this version (if not cached)
351+
if: steps.cache-tidb-version-unistore.outputs.cache-hit != 'true'
352+
run: |
353+
export PATH=$HOME/.tiup/bin:$PATH
354+
VERSION="${{ steps.extract-tidb-version-unistore.outputs.version }}"
355+
echo "Installing TiDB components for v${VERSION} (cache miss)..."
356+
tiup install tidb:v${VERSION} || true
357+
tiup install pd:v${VERSION} || true
358+
# Note: TiKV not needed for Unistore, but install for cache consistency
359+
tiup install tikv:v${VERSION} || true
360+
echo "TiDB v${VERSION} components installed and will be cached for next run"
361+
362+
- name: Run Unistore smoke tests {{ matrix.target }}
363+
env:
364+
GOFLAGS: -mod=vendor
365+
run: make ${{ matrix.target }}
251366
# DISABLED to figure out GPG signing issue on Github Actions
252367
# possibly due to lack of TTY inside docker?
253368
# release:

GNUmakefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ testtidb:
9595
MYSQL_VERSION=$(MYSQL_VERSION) MYSQL_PORT=$(MYSQL_PORT) $(CURDIR)/scripts/tidb-playground.sh stop; \
9696
exit $$TEST_RESULT
9797

98+
# Fast Unistore-based smoke tests (latest of each major series)
99+
testtidb-unistore%:
100+
$(MAKE) MYSQL_VERSION=$* MYSQL_PORT=35$(shell echo "$*" | tr -d '.') testtidb-unistore
101+
102+
# WARNING: this does not work as a bare task run, it only instantiates correctly inside the versioned TiDB task run
103+
testtidb-unistore:
104+
@MYSQL_VERSION=$(MYSQL_VERSION) MYSQL_PORT=$(MYSQL_PORT) $(CURDIR)/scripts/tidb-playground-unistore.sh start || exit 1
105+
MYSQL_USERNAME="$(TEST_USER)" MYSQL_PASSWORD="" MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT) $(MAKE) testacc; \
106+
TEST_RESULT=$$?; \
107+
MYSQL_VERSION=$(MYSQL_VERSION) MYSQL_PORT=$(MYSQL_PORT) $(CURDIR)/scripts/tidb-playground-unistore.sh stop; \
108+
exit $$TEST_RESULT
109+
98110
testmariadb%:
99111
$(MAKE) MYSQL_VERSION=$* MYSQL_PORT=6$(shell echo "$*" | tr -d '.') testmariadb
100112

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
3+
# TiDB Playground wrapper script for fast Unistore-based testing
4+
# Uses TiUP playground with Unistore backend for quick smoke tests
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+
else
20+
# Update TiUP and playground component to ensure latest version
21+
echo "Updating TiUP and playground component..."
22+
tiup update --self || true
23+
tiup update playground || true
24+
fi
25+
26+
# Create temporary TiDB config file for Unistore
27+
TIDB_CONFIG=$(mktemp)
28+
cat > "${TIDB_CONFIG}" <<EOF
29+
[store]
30+
store = "unistore"
31+
EOF
32+
33+
if [ "$MODE" = "start" ]; then
34+
echo "==> Starting TiDB Playground v${VERSION} with Unistore backend on port ${PORT}..."
35+
36+
# Clean up any existing playground instances
37+
pkill -f "tiup playground" || true
38+
sleep 1
39+
40+
# Start playground with Unistore backend
41+
# Note: Still need PD for metadata, but no TiKV needed
42+
tiup playground ${VERSION} \
43+
--db 1 \
44+
--kv 0 \
45+
--pd 1 \
46+
--tiflash 0 \
47+
--without-monitor \
48+
--host 0.0.0.0 \
49+
--db.port ${PORT} \
50+
--db.config "${TIDB_CONFIG}" \
51+
> /tmp/tidb-playground-unistore-${PORT}.log 2>&1 &
52+
53+
PLAYGROUND_PID=$!
54+
echo $PLAYGROUND_PID > /tmp/tidb-playground-unistore-${PORT}.pid
55+
56+
# Unistore starts faster, use shorter timeout (60 seconds)
57+
TIMEOUT=60
58+
echo "Waiting for TiDB with Unistore to be ready (max ${TIMEOUT} seconds)..."
59+
for i in $(seq 1 ${TIMEOUT}); do
60+
if mysql -h 127.0.0.1 -P ${PORT} -u root -e 'SELECT 1' >/dev/null 2>&1; then
61+
echo "TiDB with Unistore is ready!"
62+
rm -f "${TIDB_CONFIG}"
63+
exit 0
64+
fi
65+
sleep 1
66+
if [ $((i % 5)) -eq 0 ]; then
67+
printf "."
68+
fi
69+
done
70+
71+
echo ""
72+
echo "ERROR: TiDB with Unistore failed to start within ${TIMEOUT} seconds"
73+
echo "Last 20 lines of playground log:"
74+
tail -20 /tmp/tidb-playground-unistore-${PORT}.log || true
75+
rm -f "${TIDB_CONFIG}"
76+
exit 1
77+
78+
elif [ "$MODE" = "stop" ]; then
79+
echo "==> Stopping TiDB Playground (Unistore)..."
80+
81+
# Kill by PID if available
82+
if [ -f /tmp/tidb-playground-unistore-${PORT}.pid ]; then
83+
PID=$(cat /tmp/tidb-playground-unistore-${PORT}.pid)
84+
kill $PID 2>/dev/null || true
85+
rm /tmp/tidb-playground-unistore-${PORT}.pid
86+
fi
87+
88+
# Kill any remaining tiup playground processes
89+
pkill -f "tiup playground" || true
90+
91+
# Clean up log file and config
92+
rm -f /tmp/tidb-playground-unistore-${PORT}.log
93+
rm -f "${TIDB_CONFIG}" 2>/dev/null || true
94+
95+
echo "TiDB Playground (Unistore) stopped"
96+
fi

0 commit comments

Comments
 (0)