Skip to content

pkg/util/workloadrepo: stabilize flaky TestCreatePartition#67793

Open
flaky-claw wants to merge 2 commits intopingcap:masterfrom
flaky-claw:flakyfixer/case_8982396958ea-a1
Open

pkg/util/workloadrepo: stabilize flaky TestCreatePartition#67793
flaky-claw wants to merge 2 commits intopingcap:masterfrom
flaky-claw:flakyfixer/case_8982396958ea-a1

Conversation

@flaky-claw
Copy link
Copy Markdown
Contributor

@flaky-claw flaky-claw commented Apr 15, 2026

What problem does this PR solve?

Issue Number: close #67461

Problem Summary:
Flaky test TestCreatePartition in pkg/util/workloadrepo intermittently fails, so this PR stabilizes that path.

What changed and how does it work?

Root Cause

TEST_ISSUE: the original flake is TestCreatePartition using unstable wall-clock day boundaries, and this address round fixes only the missing Bazel strict deps introduced by the prior plain-session test fix.

Fix

Adding //pkg/session and //pkg/session/sessionapi to workloadrepo_test is necessary so the existing worker_test.go imports build under TiDB's Bazel strict-deps validation.

Verification

Spec:

  • target: pkg/util/workloadrepo :: TestCreatePartition
  • strategy: tidb.go_flaky.default
  • plan mode: BASELINE_ONLY
  • requirements: required case must execute; no skip; repeat count = 1
  • baseline gates: required_flaky_gate, build_safety_gate, intent_guard_gate

Observed result:

  • status: passed
  • required case executed: yes
  • submission decision: ALLOWED
  • scope debt present: yes
    Required flaky gate passed.
    Build safety gate passed.
    Intent guard gate passed.

Gate checklist:

  • Required flaky gate: PASS
  • Build safety gate: PASS
  • Intent guard gate: PASS
  • Repo-wide advisory gate: SKIPPED
  • Feedback specific gate: SKIPPED

Commands:

  • go test -json ./pkg/util/workloadrepo -run '^TestCreatePartition$' -count=1
  • go test -json ./pkg/util/workloadrepo -count=1
  • make build

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

Fixes #67461

Summary by CodeRabbit

  • Tests

    • Improved test infrastructure with centralized helpers and deterministic time anchoring for partition creation validation.
    • Switched test DDL execution to a session-based path to reuse sessions and reduce flakiness.
  • Chores

    • Updated test dependencies to support the new test execution flow.

@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed labels Apr 15, 2026
@pantheon-ai
Copy link
Copy Markdown

pantheon-ai Bot commented Apr 15, 2026

@flaky-claw I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details.

⏳ This process typically takes 10-30 minutes depending on the complexity of the changes.

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 15, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lonng for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 15, 2026
@tiprow
Copy link
Copy Markdown

tiprow Bot commented Apr 15, 2026

Hi @flaky-claw. 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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9c32950f-8547-4831-98f5-3bf5adb303e4

📥 Commits

Reviewing files that changed from the base of the PR and between af4b5ca and 4310e3e.

📒 Files selected for processing (1)
  • pkg/util/workloadrepo/worker_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/util/workloadrepo/worker_test.go

📝 Walkthrough

Walkthrough

Added BUILD test dependencies for session API and refactored workloadrepo tests to run DDL via sessionapi.Session (deterministic noon anchor for date partitions) instead of testkit.TestKit.

Changes

Build configuration

Layer / File(s) Summary
Build deps
pkg/util/workloadrepo/BUILD.bazel
Added test dependencies on //pkg/session and //pkg/session/sessionapi to allow using SessionAPI in tests.

Workload repo tests (partitioning)

Layer / File(s) Summary
Imports
pkg/util/workloadrepo/worker_test.go
Added sessionapi imports to support session-based DDL execution.
Shared exec helper
pkg/util/workloadrepo/worker_test.go
Added createTableWithPartsByExec to centralize building create-table SQL with partitions, executing via a provided exec function, and validating partitions.
TestKit wrapper
pkg/util/workloadrepo/worker_test.go
Refactored createTableWithParts to delegate to createTableWithPartsByExec while continuing to use tk.MustExec.
Session-based exec
pkg/util/workloadrepo/worker_test.go
Added createTableWithPartsForSession to perform partition DDL via session.MustExec on a sessionapi.Session.
Validation change
pkg/util/workloadrepo/worker_test.go
Changed validatePartitionCreation to accept sessionapi.Session and invoke session-based DDL creation.
Test entry changes
pkg/util/workloadrepo/worker_test.go
Updated TestCreatePartition to create a test session via session.CreateSession4Test, run initial DDL using session.MustExec, and set anchor time to noon for deterministic partitions; replaced relevant calls to use session-based helpers.
TIDB_STATEMENTS_STATS setup
pkg/util/workloadrepo/worker_test.go
Replaced one createTableWithParts usage with createTableWithPartsForSession so the TIDB_STATEMENTS_STATS partitioned-table is created via the session path.

Sequence Diagram(s)

(none)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • pingcap/tidb#67797: Similar test changes replacing testkit-based DDL with sessionapi.Session usage.
  • pingcap/tidb#67410: Related switch of workloadrepo tests to use pkg/session/sessionapi.Session and BUILD dependency addition.
  • pingcap/tidb#67803: Another PR converting test DDL execution from TestKit to sessionapi.Session/session.MustExec.

Suggested labels

size/S, approved, lgtm

Suggested reviewers

  • hawkingrei

Poem

🐰 I hopped through tests at break of noon,

Session in paw, no flaky tune.
Partitions firm where dates align,
Build deps set — the trees look fine.
A tiny hop, a tidy test — hooray, code's in bloom!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: stabilizing a flaky test in the workloadrepo package, which is the primary objective of this PR.
Description check ✅ Passed The description includes the required issue number, problem summary, detailed explanation of root cause and fix, verification results, completed checklist, and release notes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.1)

Command failed


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.8804%. Comparing base (324c404) to head (4310e3e).
⚠️ Report is 109 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #67793        +/-   ##
================================================
- Coverage   77.6079%   76.8804%   -0.7275%     
================================================
  Files          1982       1975         -7     
  Lines        548895     564592     +15697     
================================================
+ Hits         425986     434061      +8075     
- Misses       122099     129465      +7366     
- Partials        810       1066       +256     
Flag Coverage Δ
integration 41.3611% <ø> (+7.0214%) ⬆️

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

Components Coverage Δ
dumpling 61.5065% <ø> (ø)
parser ∅ <ø> (∅)
br 48.8908% <ø> (-11.5452%) ⬇️
🚀 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.

@yinsustart
Copy link
Copy Markdown

/test mysql-test

@tiprow
Copy link
Copy Markdown

tiprow Bot commented Apr 16, 2026

@yinsustart: 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.

Details

In response to this:

/test mysql-test

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/util/workloadrepo/worker_test.go Outdated
Comment on lines +151 to +153
func anchorPartitionTestTime(now time.Time) time.Time {
return time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, now.Location())
}
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.

I don't understand why is this necessary?

At the very least, this function is only called from one place, so it doesn't need to be a new function: just replace the function call with this code instead (and add a comment if it's still not clear what it's doing).

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.

Ah, okay I think I see now. This seems like it is ensuring that the now timestamp we use for testing is always 12:00, so that adding/subtracting days is consistent.

Please add a comment that explains this is due to the unstable wall-clock day boundaries. The name anchorPartitionTestTime by itself doesn't clearly indicate this.

Alternatively, consider using time.Round instead of doing this rounding manually.

Comment on lines +650 to +657
func createTableWithPartsForSession(ctx context.Context, t *testing.T, se sessionapi.Session, tbl *repositoryTable,
sess sessionctx.Context, partitions []time.Time) {
createSQL, err := buildCreateQuery(ctx, sess, tbl)
require.NoError(t, err)
createSQL += buildPartitionString(partitions)
session.MustExec(t, se, createSQL)
require.True(t, validatePartitionsMatchExpected(ctx, t, sess, tbl, partitions))
}
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.

This is unnecessarily copy/pasting duplicate code from createTableWithParts.

Either modify createTableWithParts to accept an optional session, or refactor the common parts of these functions into a helper function, and have both createTableWithParts and createTableWithPartsForSession call that helper function.

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.

@henrybw Thanks for the review. I addressed both comments in 4310e3e: the noon anchor is now inlined with a comment explaining the wall-clock day boundary issue, and the duplicated create-table logic is refactored into a shared helper used by both the TestKit and SessionAPI paths.

@yinsustart
Copy link
Copy Markdown

/check-issue-triage-complete

@wuhuizuo
Copy link
Copy Markdown
Contributor

wuhuizuo commented May 3, 2026

/retest

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 3, 2026

@wuhuizuo: 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.

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.

@flaky-claw flaky-claw requested a review from henrybw May 9, 2026 04:37
@yinsustart yinsustart requested a review from bb7133 May 9, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: TestCreatePartition in pkg/util/workloadrepo

4 participants