Skip to content

test: stabilize flaky TestTTLStatusCache/last_job_finish_time#69635

Open
flaky-claw wants to merge 1 commit into
pingcap:masterfrom
flaky-claw:flakyfixer/case_0702aaf8ac0a-a1
Open

test: stabilize flaky TestTTLStatusCache/last_job_finish_time#69635
flaky-claw wants to merge 1 commit into
pingcap:masterfrom
flaky-claw:flakyfixer/case_0702aaf8ac0a-a1

Conversation

@flaky-claw

@flaky-claw flaky-claw commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #69619

Problem Summary:
Flaky test TestTTLStatusCache/last_job_finish_time in pkg/ttl/cache intermittently fails, so this PR stabilizes that path.

What changed and how does it work?

Root Cause

TestTTLStatusCache used CreateMockStoreAndDomain, which starts the background TTL job manager in the test environment. After the TTL manager becomes leader, it may immediately run DoGC().

The subtests in TestTTLStatusCache insert temporary rows into mysql.tidb_ttl_table_status and previously relied on rows from earlier subtests remaining in the table. However, those rows have current_job_status IS NULL, so they can be removed by the background TTL table-status GC during the test.

As a result, later subtests may observe fewer rows than expected, making the original cumulative assertion (len(isc.Tables) == index+1) flaky.

Fix

Clearing the TTL status table inside each field subtest makes each field extraction case self-contained.

Verification

Spec:

  • target: pkg/ttl/cache :: TestTTLStatusCache/last_job_finish_time
  • strategy: tidb.issue_scoped.v2
  • plan mode: BASELINE_ONLY
  • requirements: required case must execute; no skip; repeat count = 1
  • execution surface: GO_TEST_WITH_TAGS
  • build tags: intest, deadlock
  • baseline gates: required_flaky_gate, build_safety_gate, intent_guard_gate
  • feedback surface source: baseline_only

Observed result:

  • status: failed
  • required case executed: yes
  • submission decision: ALLOWED
  • note: Required flaky case executed during validation.
    Required flaky case was not skipped.
    target_flaky_validation passed.
    package_validation passed.

Gate checklist:

  • native_repro: SKIPPED
  • target_flaky_validation: PASS
  • package_validation: PASS
  • build_safety: BLOCKED
  • ready_lint: BLOCKED
  • prow_bazel_shard: SKIPPED

Commands:

  • go test -json -tags=intest,deadlock ./pkg/ttl/cache -run '^TestTTLStatusCache/last_job_finish_time$' -count=1
  • go test -json -tags=intest,deadlock ./pkg/ttl/cache -count=1

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 #69619

Summary by CodeRabbit

  • Tests
    • Updated cache test coverage to reset table status data between subtests.
    • Strengthened assertions so each case checks a single cached table consistently, improving test reliability.

@ti-chi-bot ti-chi-bot Bot added the release-note-none Denotes a PR that doesn't merit a release note. label Jul 3, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

[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 joccau 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Modified TestTTLStatusCache in pkg/ttl/cache/ttlstatus_test.go to delete existing rows from mysql.tidb_ttl_table_status before each subtest's insert, fixed the expected cache count to 1 per subtest, and added a nil guard before asserting the retrieved table's fields.

Changes

TTL status cache test fix

Layer / File(s) Summary
Reset table state per subtest
pkg/ttl/cache/ttlstatus_test.go
Test now clears mysql.tidb_ttl_table_status before inserting each per-field row, expects exactly 1 cached table (instead of accumulating), and only runs the field assertion when the retrieved table is non-nil.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related PRs

  • pingcap/tidb#68701: Both PRs modify pkg/ttl/cache tests by manipulating mysql.tidb_ttl_table_status rows for deterministic TTL test behavior.

Suggested labels: approved, lgtm

Suggested reviewers: lcwangchao, YangKeao

Poem

A rabbit hopped through flaky rows,
Cleared the table, tidy goes,
One test, one row, no more chaos,
NotNil guards where doubt arose,
Hop hop, the cache now steady flows! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #69619 by removing shared-state dependence in TestTTLStatusCache/last_job_finish_time.
Out of Scope Changes check ✅ Passed The PR is limited to the targeted test stabilization and does not introduce unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly describes the main change: stabilizing a flaky TTL status cache test.
Description check ✅ Passed The description matches the template and includes the issue, problem summary, fix details, checklist, and release note section.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.1105%. Comparing base (8be4bd0) to head (26c741e).

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69635        +/-   ##
================================================
- Coverage   76.3268%   74.1105%   -2.2164%     
================================================
  Files          2041       2050         +9     
  Lines        560589     576524     +15935     
================================================
- Hits         427880     427265       -615     
- Misses       131808     149053     +17245     
+ Partials        901        206       -695     
Flag Coverage Δ
integration 40.6942% <ø> (+0.9890%) ⬆️

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

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 47.4650% <ø> (-15.2563%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: TestTTLStatusCache/last_job_finish_time in pkg/ttl/cache

1 participant