Skip to content

Commit 4f117a4

Browse files
authored
tests: use TiDB-like keys in next-gen integration tests (tikv#2010) (tikv#2031)
\n\nSigned-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>\nSigned-off-by: Chao Wang <cclcwangchao@hotmail.com>\n\nCo-authored-by: Ziqian Qin <eke@fastmail.com>\nCo-authored-by: Chao Wang <cclcwangchao@hotmail.com>
1 parent 520a563 commit 4f117a4

27 files changed

Lines changed: 928 additions & 846 deletions

.github/workflows/integration.yml

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -133,63 +133,3 @@ jobs:
133133
- name: Test
134134
run: gotestsum --format short-verbose -- --with-tikv
135135
working-directory: integration_tests/raw
136-
137-
integration-next-gen-tikv:
138-
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-integration-tests') && !startsWith(github.ref_name, 'release-') && !startsWith(github.base_ref, 'release-') }}
139-
runs-on: ubuntu-latest
140-
steps:
141-
- name: Checkout
142-
uses: actions/checkout@v4
143-
144-
- name: Set up Go
145-
uses: actions/setup-go@v5
146-
with:
147-
go-version: 1.25.8
148-
149-
- name: Install gotestsum
150-
run: go install gotest.tools/gotestsum@latest
151-
152-
- name: Fetch PD
153-
uses: shrink/actions-docker-extract@v1
154-
id: extract-pd
155-
with:
156-
image: pingcap/pd:nightly
157-
path: /pd-server
158-
159-
- name: Fetch Next-Gen TiKV
160-
uses: shrink/actions-docker-extract@v1
161-
id: extract-tikv
162-
with:
163-
image: gcr.io/pingcap-public/dbaas/tikv:dedicated-next-gen
164-
path: /tikv-server
165-
166-
- name: Run MinIO, PD & Next-Gen TiKV
167-
run: |
168-
mkdir -p tikv-data
169-
# Install and run minio for S3 backend
170-
curl -Lo minio https://dl.min.io/server/minio/release/linux-amd64/minio
171-
chmod +x minio
172-
mkdir -p $HOME/serverless_s3/cse-test
173-
MINIO_ROOT_USER=minioadmin MINIO_ROOT_PASSWORD=minioadmin ./minio server $HOME/serverless_s3 > minio.log 2>&1 &
174-
sleep 5
175-
# Move binaries and run servers
176-
mv ../${{steps.extract-pd.outputs.destination}}/pd-server .
177-
mv ../${{steps.extract-tikv.outputs.destination}}/tikv-server .
178-
./pd-server --config pd_next_gen.toml > pd.log 2>&1 &
179-
sleep 5
180-
./tikv-server -C tikv_next_gen.toml --pd-endpoints="127.0.0.1:2379" --addr="127.0.0.1:20160" --data-dir=${{ github.workspace }}/integration_tests/tikv-data > tikv.log 2>&1 &
181-
182-
echo "Waiting for servers to start..."
183-
sleep 15
184-
185-
echo "--- MinIO Log ---"
186-
tail minio.log || echo "minio.log not found"
187-
echo "--- PD Log ---"
188-
tail pd.log || echo "pd.log not found"
189-
echo "--- TiKV Log ---"
190-
tail tikv.log || echo "tikv.log not found"
191-
working-directory: integration_tests
192-
193-
- name: Test
194-
run: gotestsum --format short-verbose -- -parallel 1 -tags=nextgen --with-tikv --keyspace-name='keyspace1'
195-
working-directory: integration_tests

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ Prefer existing error, retry, backoff, logging, metrics, and failpoint helpers i
2525

2626
## API v2 Codec Guidelines
2727

28-
All API v2 commands that carry keys must have complete and consistent encode/decode handling in `internal/apicodec`. This includes keys, key ranges, lock information, region errors, and any request or response fields that carry encoded keys. When adding or modifying a key-bearing RPC, update both request and response paths, add table-driven coverage in `internal/apicodec`, and verify that encode/decode behavior is symmetric. Missing or one-sided handling can create key-format mismatches and correctness bugs, especially across TiKV and CSE paths.
28+
All API v2 commands that carry keys must have complete and consistent encode/decode handling in `internal/apicodec`. This includes keys, key ranges, lock information, region errors, and any request or response fields that carry encoded keys. When adding or modifying a key-bearing RPC, update both request and response paths, add table-driven coverage in `internal/apicodec`, and verify that encode/decode behavior is symmetric. Missing or one-sided handling can create key-format mismatches and correctness bugs, especially across TiKV and CSE paths. When adding or modifying a `tikvrpc.Cmd*` whose request has a context field, update `tikvrpc/gen.sh`, regenerate `tikvrpc/cmds_generated.go`, and add `AttachContext` coverage.
2929

3030
## Testing Guidelines
3131

3232
Use Go's `testing` package with `testify/require`, `testify/assert`, and `testify/suite`, matching nearby tests. Name tests `TestXxx` and keep suite types in the existing lowercase style, such as `testRawkvSuite` or `testSnapshotSuite`.
3333

3434
Add or update package-level tests for every behavior change. Use `integration_tests/` when behavior depends on TiKV, PD, transactions, lock resolution, failpoints, or API-version behavior that mocks cannot cover. For concurrency-sensitive changes, run the race command before opening a PR.
3535

36+
CSE is only used behind TiDB. Transactional integration tests that run against next-gen/CSE should generate keys through a TiDB-like mem-comparable helper such as `encodeKey(...)`, not raw ad-hoc keys like `[]byte("k")`. For split/range/order-sensitive tests, update data keys, split keys, range bounds, and expected keys together.
37+
3638
## Commit & Pull Request Guidelines
3739

3840
Recent commits use concise, imperative subjects scoped by package or area, for example `apicodec: cover remaining API v2 key-bearing commands` or `txnkv: enable TiKV-side async resolve region lock for read path`. Follow that pattern and reference issues or PRs when relevant. This repository has DCO checks enabled; create commits with `git commit -s` so the commit message includes the required `Signed-off-by` trailer.

integration_tests/1pc_test.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ func (s *testOnePCSuite) TearDownTest() {
6464
s.testAsyncCommitCommon.tearDownTest()
6565
}
6666

67+
func (s *testOnePCSuite) key(name string) []byte {
68+
return encodeKey("~1pc", name)
69+
}
70+
6771
func (s *testOnePCSuite) Test1PC() {
68-
k1 := []byte("k1")
72+
k1 := s.key("k1")
6973
v1 := []byte("v1")
7074

7175
txn := s.begin1PC()
@@ -81,7 +85,7 @@ func (s *testOnePCSuite) Test1PC() {
8185

8286
// 1PC doesn't work if 1PC option is not set
8387

84-
k2 := []byte("k2")
88+
k2 := s.key("k2")
8589
v2 := []byte("v2")
8690

8791
txn = s.begin()
@@ -94,11 +98,11 @@ func (s *testOnePCSuite) Test1PC() {
9498
s.Greater(txn.GetCommitter().GetCommitTS(), txn.StartTS())
9599

96100
// Test multiple keys
97-
k3 := []byte("k3")
101+
k3 := s.key("k3")
98102
v3 := []byte("v3")
99-
k4 := []byte("k4")
103+
k4 := s.key("k4")
100104
v4 := []byte("v4")
101-
k5 := []byte("k5")
105+
k5 := s.key("k5")
102106
v5 := []byte("v5")
103107

104108
txn = s.begin1PC()
@@ -148,7 +152,7 @@ func (s *testOnePCSuite) Test1PC() {
148152
}
149153

150154
func (s *testOnePCSuite) Test1PCIsolation() {
151-
k := []byte("k")
155+
k := s.key("isolation_k")
152156
v1 := []byte("v1")
153157

154158
txn := s.begin1PC()
@@ -189,27 +193,28 @@ func (s *testOnePCSuite) Test1PCDisallowMultiRegion() {
189193

190194
txn := s.begin1PC()
191195

192-
keys := []string{"k0", "k1", "k2", "k3"}
196+
keyNames := []string{"k0", "k1", "k2", "k3"}
197+
keys := [][]byte{s.key(keyNames[0]), s.key(keyNames[1]), s.key(keyNames[2]), s.key(keyNames[3])}
193198
values := []string{"v0", "v1", "v2", "v3"}
194199

195-
err := txn.Set([]byte(keys[0]), []byte(values[0]))
200+
err := txn.Set(keys[0], []byte(values[0]))
196201
s.Nil(err)
197-
err = txn.Set([]byte(keys[3]), []byte(values[3]))
202+
err = txn.Set(keys[3], []byte(values[3]))
198203
s.Nil(err)
199204
err = txn.Commit(context.Background())
200205
s.Nil(err)
201206

202207
// 1PC doesn't work if it affects multiple regions.
203-
loc, err := s.store.GetRegionCache().LocateKey(s.bo, []byte(keys[2]))
208+
loc, err := s.store.GetRegionCache().LocateKey(s.bo, keys[2])
204209
s.Nil(err)
205210
newRegionID := s.cluster.AllocID()
206211
newPeerID := s.cluster.AllocID()
207-
s.cluster.Split(loc.Region.GetID(), newRegionID, []byte(keys[2]), []uint64{newPeerID}, newPeerID)
212+
s.cluster.Split(loc.Region.GetID(), newRegionID, keys[2], []uint64{newPeerID}, newPeerID)
208213

209214
txn = s.begin1PC()
210-
err = txn.Set([]byte(keys[1]), []byte(values[1]))
215+
err = txn.Set(keys[1], []byte(values[1]))
211216
s.Nil(err)
212-
err = txn.Set([]byte(keys[2]), []byte(values[2]))
217+
err = txn.Set(keys[2], []byte(values[2]))
213218
s.Nil(err)
214219
err = txn.Commit(context.Background())
215220
s.Nil(err)
@@ -221,7 +226,7 @@ func (s *testOnePCSuite) Test1PCDisallowMultiRegion() {
221226
s.Nil(err)
222227
snap := s.store.GetSnapshot(ver)
223228
for i, k := range keys {
224-
v, err := snap.Get(context.Background(), []byte(k))
229+
v, err := snap.Get(context.Background(), k)
225230
s.Nil(err)
226231
s.Equal(v.Value, []byte(values[i]))
227232
}
@@ -232,9 +237,9 @@ func (s *testOnePCSuite) Test1PCDisallowMultiRegion() {
232237
func (s *testOnePCSuite) Test1PCLinearizability() {
233238
t1 := s.begin()
234239
t2 := s.begin()
235-
err := t1.Set([]byte("a"), []byte("a1"))
240+
err := t1.Set(s.key("linear_a"), []byte("a1"))
236241
s.Nil(err)
237-
err = t2.Set([]byte("b"), []byte("b1"))
242+
err = t2.Set(s.key("linear_b"), []byte("b1"))
238243
s.Nil(err)
239244
// t2 commits earlier than t1
240245
err = t2.Commit(context.Background())
@@ -253,15 +258,15 @@ func (s *testOnePCSuite) Test1PCWithMultiDC() {
253258
}
254259

255260
localTxn := s.begin1PC()
256-
err := localTxn.Set([]byte("a"), []byte("a1"))
261+
err := localTxn.Set(s.key("multi_dc_a"), []byte("a1"))
257262
localTxn.SetScope("bj")
258263
s.Nil(err)
259264
err = localTxn.Commit(context.Background())
260265
s.Nil(err)
261266
s.False(localTxn.GetCommitter().IsOnePC())
262267

263268
globalTxn := s.begin1PC()
264-
err = globalTxn.Set([]byte("b"), []byte("b1"))
269+
err = globalTxn.Set(s.key("multi_dc_b"), []byte("b1"))
265270
globalTxn.SetScope(oracle.GlobalTxnScope)
266271
s.Nil(err)
267272
err = globalTxn.Commit(context.Background())
@@ -274,7 +279,7 @@ func (s *testOnePCSuite) TestTxnCommitCounter() {
274279

275280
// 2PC
276281
txn := s.begin()
277-
err := txn.Set([]byte("k"), []byte("v"))
282+
err := txn.Set(s.key("counter_k"), []byte("v"))
278283
s.Nil(err)
279284
err = txn.Commit(context.Background())
280285
s.Nil(err)
@@ -286,7 +291,7 @@ func (s *testOnePCSuite) TestTxnCommitCounter() {
286291

287292
// AsyncCommit
288293
txn = s.beginAsyncCommit()
289-
err = txn.Set([]byte("k1"), []byte("v1"))
294+
err = txn.Set(s.key("counter_k1"), []byte("v1"))
290295
s.Nil(err)
291296
err = txn.Commit(context.Background())
292297
s.Nil(err)
@@ -298,7 +303,7 @@ func (s *testOnePCSuite) TestTxnCommitCounter() {
298303

299304
// 1PC
300305
txn = s.begin1PC()
301-
err = txn.Set([]byte("k2"), []byte("v2"))
306+
err = txn.Set(s.key("counter_k2"), []byte("v2"))
302307
s.Nil(err)
303308
err = txn.Commit(context.Background())
304309
s.Nil(err)
@@ -314,7 +319,7 @@ func (s *testOnePCSuite) TestFailWithUndeterminedResult() {
314319
s.T().Skip("not supported in real TiKV")
315320
}
316321
txn := s.begin1PC()
317-
s.Nil(txn.Set([]byte("key"), []byte("value")))
322+
s.Nil(txn.Set(s.key("undetermined_key"), []byte("value")))
318323
s.Nil(failpoint.Enable(
319324
"tikvclient/rpcPrewriteResult",
320325
// it will make the prewrite in 1pc fail.

0 commit comments

Comments
 (0)