Skip to content

test: stabilize TestClusterIDInReq#1894

Open
lance6716 wants to merge 2 commits intotikv:masterfrom
lance6716:codex/fix-clusterid-flaky-test
Open

test: stabilize TestClusterIDInReq#1894
lance6716 wants to merge 2 commits intotikv:masterfrom
lance6716:codex/fix-clusterid-flaky-test

Conversation

@lance6716
Copy link
Contributor

@lance6716 lance6716 commented Feb 11, 2026

close #1893

What

  • keep TestClusterIDInReq on MockTikvService (no test simplification to pure stub)
  • keep asserting ClusterId > 0 in the wrapped fnClient
  • replace the fragile probe flow (SendReq + 10ms timeout) with:
    • a readiness wait via rpcClient.SendRequest + Eventually
    • a normal assertion request with time.Second timeout

Why

The old test path occasionally hit startup/timing races under -race, and could return a pseudo region error (EpochNotMatch) before the assertion path was stable.

Result

  • still validates cluster-id propagation against MockTikvService
  • avoids timing-sensitive false failures in CI
  • verified with:
    • go test -race ./internal/locate -run TestRegionRequestToSingleStore/TestClusterIDInReq -count=300 -failfast
    • go test -race ./internal/locate

Summary by CodeRabbit

  • Tests
    • Tightened assertions to be more precise and robust.
    • Replaced an ad-hoc readiness probe with a deterministic wait-before-run approach to start the test flow.
    • Overall improved test stability and reduced flakiness in request-timing scenarios.

Copilot AI review requested due to automatic review settings February 11, 2026 02:51
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 11, 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 lykxsassinator 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 dco-signoff: yes Indicates the PR's author has signed the dco. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 11, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Replace the explicit probe SendReq in TestClusterIDInReq with an Eventually readiness loop that retries SendRequest until the server loop is ready; change the ClusterId assertion to a greater-than-0 check and perform the final SendReq with a 1s timeout after readiness is observed.

Changes

Cohort / File(s) Summary
Region request test
internal/locate/region_request_test.go
Assert req.ClusterId > 0 (uint64); remove separate probe SendReq; add an Eventually/wait loop that retries SendRequest until server readiness; keep final SendReq with a 1s timeout. Timing/control-flow adjustments in the test.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size/M, contribution

Suggested reviewers

  • lcwangchao
  • MyonKeminta

Poem

🐰
I waited patient, tiny paws in place,
No noisy probe to start the race.
Cluster IDs checked, the loop runs tight,
At last the request hops into light. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: stabilize TestClusterIDInReq' directly and accurately summarizes the main change—stabilizing a flaky test.
Linked Issues check ✅ Passed The PR fully addresses issue #1893 by replacing the fragile probe flow with an explicit readiness wait using Eventually and a stable assertion request, eliminating flakiness caused by startup/timing races.
Out of Scope Changes check ✅ Passed All changes are directly scoped to stabilizing TestClusterIDInReq; no unrelated modifications to other tests, production code, or unrelated functionality are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


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.

Copy link

Copilot AI left a comment

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 stabilizes the TestClusterIDInReq test by removing its dependency on a real mock gRPC server and network timing. The test now uses a simple inline function stub to validate request metadata, making it deterministic and eliminating CI flakiness.

Changes:

  • Replaced mock gRPC server setup with an inline fnClient stub
  • Removed probe request and cleanup code that was causing timing-related flakiness
  • Changed timeout from 10ms to 1 second since timeout behavior is no longer being tested

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lance6716 lance6716 changed the title test: stabilize TestClusterIDInReq 【WIP】test: stabilize TestClusterIDInReq Feb 11, 2026
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 11, 2026
@lance6716 lance6716 changed the title 【WIP】test: stabilize TestClusterIDInReq test: stabilize TestClusterIDInReq Feb 11, 2026
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 11, 2026
@lance6716 lance6716 changed the title test: stabilize TestClusterIDInReq [WIP] test: stabilize TestClusterIDInReq Feb 11, 2026
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 11, 2026
@lance6716 lance6716 changed the title [WIP] test: stabilize TestClusterIDInReq test: stabilize TestClusterIDInReq Feb 11, 2026
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 11, 2026
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
@lance6716 lance6716 force-pushed the codex/fix-clusterid-flaky-test branch from 8729986 to b8bcdaf Compare February 11, 2026 03:43
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. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky test TestRegionRequestToSingleStore/TestClusterIDInReq

1 participant