Skip to content

tests: improve timing robustness in TestStaleReadAllCombinations - #63196

Merged
ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
ekexium:test-relax-stale-read
Sep 20, 2025
Merged

ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
ekexium:test-relax-stale-read

Conversation

@ekexium

@ekexium ekexium commented Aug 26, 2025 •

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #63271

Problem Summary:

The TestStaleReadAllCombinations/tidb_read_staleness test case is flaky under high CI load due to tight timing constraints.

What changed and how does it work?

Changes made:

  1. Relax the time constraints
  2. Reorder cases, to run tidb_read_staleness cases first

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

None

Fix flakiness in TestStaleReadAllCombinations/tidb_read_staleness under
high CI load by:
- Increasing sleep intervals from 1s to 3s for better timing separation
- Adjusting timestamp offsets proportionally to maintain test logic
- Increasing staleness buffer from +1s to +2s for more timing margin

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: ekexium <eke@fastmail.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/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 26, 2025
@hawkingrei hawkingrei added the skip-issue-check Indicates that a PR no need to check linked issue. label Aug 26, 2025
@codecov

codecov Bot commented Aug 26, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.5182%. Comparing base (d3a8bdc) to head (f854f0f).
⚠️ Report is 145 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #63196        +/-   ##
================================================
+ Coverage   72.8055%   73.5182%   +0.7127%     
================================================
  Files          1828       1844        +16     
  Lines        494865     518436     +23571     
================================================
+ Hits         360289     381145     +20856     
- Misses       112689     115021      +2332     
- Partials      21887      22270       +383     
Flag Coverage Δ
integration 42.0832% <ø> (?)
unit 72.5778% <ø> (+0.3117%) ⬆️

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

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 45.9655% <ø> (-0.3737%) ⬇️
🚀 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.

@ekexium

ekexium commented Aug 26, 2025

Copy link
Copy Markdown
Member Author

/retest

@ekexium
ekexium requested review from hawkingrei and you06 August 26, 2025 05:25
@terry1purcell

Copy link
Copy Markdown
Contributor

/retest-required

time.Sleep(1000 * time.Millisecond)
firstTime := time.Now().Add(-500 * time.Millisecond)
time.Sleep(3000 * time.Millisecond) // Increased from 1s to 3s for better timing separation
firstTime := time.Now().Add(-1500 * time.Millisecond) // Adjusted offset

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.

What about calculating the ts from PD tso?

Suggested change
firstTime := time.Now().Add(-1500 * time.Millisecond) // Adjusted offset
ts, err := tk.Session().GetStore().GetOracle().GetTimestamp(context.Background(), &oracle.Option{})
require.NoError(t, err)
firstTime := oracle.GetTimeFromTS(ts).Add(-1500 * time.Millisecond) // Adjusted offset

time.Sleep(1000 * time.Millisecond)
secondTime := time.Now().Add(-500 * time.Millisecond)
time.Sleep(3000 * time.Millisecond) // Increased from 1s to 3s
secondTime := time.Now().Add(-1500 * time.Millisecond) // Adjusted offset

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.

Ditto.

Suggested change
secondTime := time.Now().Add(-1500 * time.Millisecond) // Adjusted offset
ts, err = tk.Session().GetStore().GetOracle().GetTimestamp(context.Background(), &oracle.Option{})
require.NoError(t, err)
secondTime := oracle.GetTimeFromTS(ts).Add(-1500 * time.Millisecond) // Adjusted offset

staleness := row2CreatedElapsed + 1 // The time `now - staleness(second)` is between row1 and row2.
// Ensure sufficient buffer: with 3s sleep intervals, elapsed should be ~3s
// Adding 2s buffer ensures stale read is safely before row2 insertion
staleness := row2CreatedElapsed + 2

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.

And get the row2CreatedElapsed from PD tso.

tk.MustExec("insert into t values (1, 10)")
time.Sleep(1000 * time.Millisecond)
firstTime := time.Now().Add(-500 * time.Millisecond)
time.Sleep(3000 * time.Millisecond) // Increased from 1s to 3s for better timing separation

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.

can we use failpoint to add some hook, to make sure async actions are done?

@ekexium

ekexium commented Sep 4, 2025

Copy link
Copy Markdown
Member Author

Looks like stale read tests are stabilized now in CI. Close this for now. Reconsider these change when needed

@ekexium ekexium closed this Sep 4, 2025
@ekexium ekexium reopened this Sep 17, 2025
@ekexium

ekexium commented Sep 17, 2025

Copy link
Copy Markdown
Member Author

/check-issue-triage-complete

@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/needs-triage-completed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 17, 2025
@ekexium

ekexium commented Sep 17, 2025 •

Copy link
Copy Markdown
Member Author

I guess the key is not about timing, but slow executions of so many permutations affecting tidb_read_staleness tests. I put them first. cc @you06 @lance6716

@ekexium
ekexium force-pushed the test-relax-stale-read branch from 0478b57 to 5d2d713 Compare September 17, 2025 10:10
Signed-off-by: ekexium <eke@fastmail.com>
@ekexium
ekexium force-pushed the test-relax-stale-read branch from 5d2d713 to f67de14 Compare September 17, 2025 11:00
@ekexium

ekexium commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

/retest-required

Signed-off-by: ekexium <eke@fastmail.com>
@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 18, 2025
if err != nil {
t.Fatalf("failed to get TSO: %v", err)
}
time.Sleep(3000 * time.Millisecond) // Increased from 1s to 3s for better timing separation

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.

Is the purpose to ensure the firstTime to be after the insertion? How about using tidb_last_txn_info to get the commit ts of the insertion, and wait until the current ts - the gap exceed the commit ts? I guess in this way we won't need to use up the 3s when the test environment is stable enough.

@ti-chi-bot

ti-chi-bot Bot commented Sep 19, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MyonKeminta, you06

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 19, 2025
@ti-chi-bot

ti-chi-bot Bot commented Sep 19, 2025

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2025-09-18 11:55:49.718301482 +0000 UTC m=+100911.196882149: ☑️ agreed by you06.
  • 2025-09-19 06:23:08.601291729 +0000 UTC m=+167350.079872376: ☑️ agreed by MyonKeminta.

@ekexium

ekexium commented Sep 19, 2025

Copy link
Copy Markdown
Member Author

/retest-required

3 similar comments
@ekexium

ekexium commented Sep 19, 2025

Copy link
Copy Markdown
Member Author

/retest-required

@ekexium

ekexium commented Sep 19, 2025

Copy link
Copy Markdown
Member Author

/retest-required

@ekexium

ekexium commented Sep 20, 2025

Copy link
Copy Markdown
Member Author

/retest-required

@tiprow

tiprow Bot commented Sep 20, 2025

Copy link
Copy Markdown

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

Test name Commit Details Required Rerun command
tidb_parser_test f854f0f link true /test tidb_parser_test
fast_test_tiprow f854f0f 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 merged commit 6f7a47a into pingcap:master Sep 20, 2025
26 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm 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. skip-issue-check Indicates that a PR no need to check linked issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky test TestStaleReadAllCombinations

6 participants