Skip to content

tests: check completed leader handoff in TSO startup test - #11255

Open
rleungx wants to merge 1 commit into
tikv:masterfrom
rleungx:fix-raft-cluster-tso-leader-transfer
Open

rleungx wants to merge 1 commit into
tikv:masterfrom
rleungx:fix-raft-cluster-tso-leader-transfer

Conversation

@rleungx

@rleungx rleungx commented Sep 15, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: ref #8836

TestRaftClusterStartTSOJob can fail on a leader-transfer timeout even after another peer has become leader. In the failing CI run, the campaign loop superseded the test's transfer to pd3 with a transfer to pd1. The original request timed out while waiting for its specific target, so the test stopped before checking TSO allocator shutdown.

What is changed and how does it work?

Request resignation from the captured original leader and wait for all servers
to agree on a different leader before checking that the old TSO allocator is
uninitialized. Include the resignation error in the leader-change assertion's
failure message.

The four startup scenarios and existing allocator assertions are preserved. The test still fails if leadership does not change.

Check List

Tests

  • Unit test: TestRaftClusterStartTSOJob, 3 runs each with -race -tags deadlock and -race -tags deadlock,nextgen.
  • Baseline comparison: 3 runs with -race -tags deadlock,nextgen.
  • Controlled regression: after a real leader transfer, inject the timeout response; the original test fails and the updated test passes.
  • Negative check: acknowledge resignation without changing leadership; the updated test fails at WaitLeaderChange.
  • make check with golangci-lint v2.6.0.

The CI timing did not reproduce in the unmodified baseline runs; the controlled regression validates the observed completed-transfer/error-response outcome. Fault injection is confined to disposable validation worktrees.

Release note

None.

Summary by CodeRabbit

  • Tests
    • Improved cluster leadership-change test reliability by explicitly waiting for leadership transition completion.
    • Leadership resignation errors are now included in test assertions.

Signed-off-by: Ryan Leung <rleungx@gmail.com>
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 15, 2026
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ae4c5d42-f7d1-4fe6-9830-8369bf1dda37

📥 Commits

Reviewing files that changed from the base of the PR and between ef560c8 and 79b3350.

📒 Files selected for processing (1)
  • tests/server/cluster/cluster_test.go

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

TestRaftClusterStartTSOJob now explicitly resigns the original leader and waits for the completed leadership change. The assertion also records any resignation error.

Changes

Leadership change testing

Layer / File(s) Summary
Synchronize leader resignation
tests/server/cluster/cluster_test.go
The test replaces the generic resignation and leader wait with leaderServer.ResignLeader() and WaitLeaderChange(name). The assertion includes any resignation error.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: jmpotato

Merge Risk: ⚪ Minimal · up to 79b33

This test-only synchronization change has no identified merge-blocking behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the test change and the completed leader handoff it verifies.
Description check ✅ Passed The description includes the issue reference, problem, implementation details, validation results, checklist information, and release note. It matches the required template and provides sufficient con…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
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.

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.

@ti-chi-bot

ti-chi-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai[bot]: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

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 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: coderabbitai[bot]
Once this PR has been reviewed and has the lgtm label, please assign andremouche 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

@rleungx

rleungx commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

/retest

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.74%. Comparing base (ef560c8) to head (79b3350).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11255   +/-   ##
=======================================
  Coverage   79.73%   79.74%           
=======================================
  Files         546      546           
  Lines       79262    79262           
=======================================
+ Hits        63203    63206    +3     
+ Misses      11686    11675   -11     
- Partials     4373     4381    +8     
Flag Coverage Δ
unittests 79.74% <ø> (+<0.01%) ⬆️

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

🚀 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

dco-signoff: yes Indicates the PR's author has signed the dco. 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.

1 participant