Skip to content

test: fix part of unit tests for next-gen#63192

Merged
ti-chi-bot[bot] merged 18 commits into
pingcap:masterfrom
tangenta:next-gen-fix-unit-test-2
Aug 29, 2025
Merged

test: fix part of unit tests for next-gen#63192
ti-chi-bot[bot] merged 18 commits into
pingcap:masterfrom
tangenta:next-gen-fix-unit-test-2

Conversation

@tangenta

@tangenta tangenta commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #61702

Problem Summary:

There are many unit tests failures in next-gen build.

What changed and how does it work?

  • Replace mockstore.NewMockStore with teststore.NewMockStoreWithoutBootstrap to inject next-gen configuration code.
  • Create mysql and sys database in schema checker, to fix bootstrapping "system db not found" error in the tests with mockstore.WithSchemaChecker().
  • Encode with keyspace before using Cluster.SplitKeys() in tests.
  • Skip tests that changing tidb_enable_metadata_lock as next-gen doesn't support.
  • Fix the query result about system tables because the job/table ID for system tables are changed(ddl_jobs, statements_summary).
  • Encode with keyspace before using /mvcc/hex/ HTTP API in tests.
  • Fix unistore index key handling in indexScanProcessCore and (e *indexScanExec) Process

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 26, 2025
@tiprow

tiprow Bot commented Aug 26, 2025

Copy link
Copy Markdown

Hi @tangenta. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@codecov

codecov Bot commented Aug 26, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.14754% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.7288%. Comparing base (032d5f8) to head (a6017cd).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #63192        +/-   ##
================================================
+ Coverage   72.7920%   74.7288%   +1.9367%     
================================================
  Files          1831       1877        +46     
  Lines        495455     503697      +8242     
================================================
+ Hits         360652     376407     +15755     
+ Misses       112879     103882      -8997     
- Partials      21924      23408      +1484     
Flag Coverage Δ
integration 48.4748% <9.6153%> (?)
unit 72.2390% <31.1475%> (-0.0260%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 63.1305% <ø> (+16.8025%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: tangenta <tangenta@126.com>

if kerneltype.IsNextGen() {
testenv.UpdateConfigForNextgen(t)
config.UpdateGlobal(func(conf *config.Config) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why inline it?

we need to revert the global config back, to make sure tests depends on it work

@tangenta tangenta Aug 27, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function only provides the default case of mockstore.NewMockStore for next-gen. If there are some tests depending on the global config, maybe use mockstore.NewMockStore directly and call config.updateGlobal explicitly.

@wuhuizuo

Copy link
Copy Markdown
Contributor

/test pull-unit-test-next-gen

@tiprow

tiprow Bot commented Aug 27, 2025

Copy link
Copy Markdown

@wuhuizuo: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/test pull-unit-test-next-gen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Signed-off-by: tangenta <tangenta@126.com>
@tangenta

Copy link
Copy Markdown
Contributor Author

/test pull-unit-test-next-gen

@tiprow

tiprow Bot commented Aug 27, 2025

Copy link
Copy Markdown

@tangenta: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/test pull-unit-test-next-gen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Signed-off-by: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 27, 2025
@wuhuizuo

Copy link
Copy Markdown
Contributor

/test pull-unit-test-next-gen

@tiprow

tiprow Bot commented Aug 27, 2025

Copy link
Copy Markdown

@wuhuizuo: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/test pull-unit-test-next-gen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Comment thread pkg/executor/importer/import_test.go Outdated
Comment thread pkg/session/bootstrap.go Outdated
Signed-off-by: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 27, 2025
@tangenta tangenta mentioned this pull request Aug 27, 2025
13 tasks
Signed-off-by: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 27, 2025
@wuhuizuo

Copy link
Copy Markdown
Contributor

/test pull-unit-test-next-gen

@wuhuizuo

Copy link
Copy Markdown
Contributor

/review default

@ti-chi-bot ti-chi-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review: test: fix rest unit test for next-gen

General Observations:

  1. The PR introduces changes related to the "next-gen" feature flag (kerneltype.IsNextGen()).
  2. teststore.NewMockStoreWithoutBootstrap replaces calls to mockstore.NewMockStore in several places.
  3. Includes new logic for handling key decoding in closure_exec.go and mpp_exec.go considering API V2.
  4. Adds conditional checks for next-gen scenarios in unit tests, skipping certain tests or altering expectations.
  5. Minor adjustments to Bazel build files to include new dependencies.
  6. The PR description lacks clarity on what was changed and why, and the release note is set to "None".

Potential Problems:

1. Incomplete PR Description

  • The PR description does not explain the rationale behind the changes or provide adequate context about the "next-gen" integration. This makes it harder to evaluate the scope and potential side effects.

Suggestions:

  • Update the PR description to include:
    • Why the next-gen changes were necessary.
    • A summary of key changes and their rationale.
    • Any potential backward compatibility issues or risks.

2. Use of Conditional Checks (kerneltype.IsNextGen())

  • The use of kerneltype.IsNextGen() is pervasive and introduces branching logic throughout the codebase, which can make maintenance challenging over time.
  • Some of the conditional logic appears repetitive (e.g., handling key decoding).

Suggestions:

  • Consider centralizing next-gen specific logic into a utility function or module to reduce redundancy and improve readability.
  • Document the behavior of kerneltype.IsNextGen() and its expected impact, especially for tests.

3. Key Decoding Logic

  • The key decoding logic in closure_exec.go and mpp_exec.go introduces new handling for API V2 keys. While necessary for next-gen, this logic introduces complexity and error-prone manual checks for key prefixes.

Suggestions:

  • Extract key decoding logic into a reusable helper function.
  • Add comprehensive unit tests for the helper function to ensure correct behavior for various key formats and edge cases.

4. Test Adjustments

  • Several tests now include t.Skip() calls when `kerneltype.IsNextGen
    ......

Response is trunked for length limits.

@tiprow

tiprow Bot commented Aug 29, 2025

Copy link
Copy Markdown

@wuhuizuo: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/test pull-unit-test-next-gen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes rest unit tests for the next-gen system by adapting test expectations and infrastructure to handle differences between regular and next-gen modes. The changes primarily address differences in execution plans, key encoding, and system table configurations.

Key changes include:

  • Conditional test assertions based on kernel type for different execution plans in next-gen vs regular mode
  • Updated mock store creation to use teststore.NewMockStoreWithoutBootstrap for next-gen compatibility
  • Improved key handling in coprocessor handlers to properly decode API V2 keys

Reviewed Changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/util/stmtsummary/v2/tests/table_test.go Added next-gen conditional checks for execution plan differences
pkg/testkit/mockstore.go Updated to use teststore.NewMockStoreWithoutBootstrap for next-gen
pkg/store/mockstore/teststore/store.go Refactored to remove testing dependency and handle next-gen config
pkg/store/mockstore/unistore/cophandler/mpp_exec.go Improved key decoding for API V2 compatibility
pkg/store/mockstore/unistore/cophandler/closure_exec.go Enhanced key handling for next-gen compatibility
Multiple test files Added kerneltype imports and next-gen conditional logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/store/mockstore/teststore/store.go
Comment on lines 297 to 309
func (e *indexScanExec) Process(key, value []byte) error {
if kerneltype.IsNextGen() && len(key) > 4 && key[0] == 'x' {
key = key[4:] // remove the keyspace prefix
decodedKey := key
if !kv.Key(key).HasPrefix(tablecodec.TablePrefix()) {
// If the key is in API V2, then ignore the prefix
_, k, err := tikv.DecodeKey(key, kvrpcpb.APIVersion_V2)
if err != nil {
return errors.Trace(err)
}
decodedKey = k
if !kv.Key(decodedKey).HasPrefix(tablecodec.TablePrefix()) {
return errors.Errorf("invalid index key %q after decoded", key)
}
}

Copilot AI Aug 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key decoding logic is duplicated between mpp_exec.go and closure_exec.go. Consider extracting this logic into a shared helper function to avoid code duplication and make maintenance easier.

Copilot uses AI. Check for mistakes.
}

hexKey := p2.Key
if kerneltype.IsNextGen() {

Copilot AI Aug 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic behavior of encoding 'nil' to get a key prefix is unclear. Consider adding a comment explaining why encoding nil produces the desired prefix, or use a more explicit method to obtain the codec prefix.

Suggested change
if kerneltype.IsNextGen() {
if kerneltype.IsNextGen() {
// EncodeKey(nil) returns the codec's key prefix. We use this to strip the prefix from the hex key.

Copilot uses AI. Check for mistakes.
@wuhuizuo

Copy link
Copy Markdown
Contributor

/retest

@tiprow

tiprow Bot commented Aug 29, 2025

Copy link
Copy Markdown

@wuhuizuo: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@D3Hunter

Copy link
Copy Markdown
Contributor

/retest

@tiprow

tiprow Bot commented Aug 29, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 29, 2025
@tangenta tangenta changed the title test: fix rest unit test for next-gen test: fix part of unit tests for next-gen Aug 29, 2025
@ti-chi-bot

ti-chi-bot Bot commented Aug 29, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, YuJuncen

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 29, 2025
@ti-chi-bot

ti-chi-bot Bot commented Aug 29, 2025

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2025-08-29 03:59:48.481108848 +0000 UTC m=+499080.358939792: ☑️ agreed by D3Hunter.
  • 2025-08-29 04:03:16.686390181 +0000 UTC m=+499288.564221135: ☑️ agreed by YuJuncen.

@tiprow

tiprow Bot commented Aug 29, 2025

Copy link
Copy Markdown

@tangenta: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow a6017cd link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@ti-chi-bot

ti-chi-bot Bot commented Aug 29, 2025

Copy link
Copy Markdown

@tangenta: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
non-block/pull-unit-test-next-gen 0eac3eb link false /test pull-unit-test-next-gen

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@D3Hunter

Copy link
Copy Markdown
Contributor

/retest

@tiprow

tiprow Bot commented Aug 29, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot merged commit 98bbd14 into pingcap:master Aug 29, 2025
33 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm nextgen Indicates that the Issue or PR belongs to the nextgen kernel architecture. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants