Skip to content

test: fix flaky test TestSendRequestAsyncAndCloseClientOnHandle#1889

Open
lance6716 wants to merge 1 commit intotikv:masterfrom
lance6716:fix-1887
Open

test: fix flaky test TestSendRequestAsyncAndCloseClientOnHandle#1889
lance6716 wants to merge 1 commit intotikv:masterfrom
lance6716:fix-1887

Conversation

@lance6716
Copy link
Contributor

@lance6716 lance6716 commented Feb 10, 2026

close #1887

fixed by codex

Summary by CodeRabbit

  • Tests
    • Improved test synchronization and race condition handling to ensure reliable client shutdown validation during in-flight operations.

Signed-off-by: lance6716 <lance6716@gmail.com>
Copilot AI review requested due to automatic review settings February 10, 2026 14:04
@ti-chi-bot ti-chi-bot bot added the dco-signoff: yes Indicates the PR's author has signed the dco. label Feb 10, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 10, 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 cfzjywxk 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

@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

This change fixes a flaky test by introducing synchronization mechanisms to eliminate race conditions. A handleEntered channel and handleCtx are added to coordinate the mock server handle startup and client closure, ensuring deterministic test execution.

Changes

Cohort / File(s) Summary
Test Synchronization
internal/client/client_async_test.go
Added handleCtx cancellation context and handleEntered channel to synchronize mock server handle entry. Modified handle goroutine to signal entry and block until context cancellation. Updated test flow to wait for handle startup before closing client, preventing race conditions that caused flaky test failures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A flaky test once caused us despair,
Race conditions floating through the air—
With channels and contexts, we synchronized the way,
Now the handle and close work in harmony today! ✨

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the fix for a flaky test by name, accurately reflecting the main change in the changeset.
Linked Issues check ✅ Passed The PR adds synchronization to prevent race conditions and ensure deterministic test behavior, directly addressing the flakiness root cause [#1887].
Out of Scope Changes check ✅ Passed All changes are contained to the test file with synchronization mechanisms to fix the flaky test; no unrelated or out-of-scope modifications are present.

✏️ 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.

@ti-chi-bot ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 10, 2026
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

Stabilizes the flaky TestSendRequestAsyncAndCloseClientOnHandle by making the test deterministically wait until the mock server has actually received the async batch request before closing the RPC client, matching the scenario the test intends to validate.

Changes:

  • Replace timing-based time.Sleep/time.AfterFunc sequencing with an explicit “handler entered” signal from the mock server.
  • Block the mock handler on a cancellable context so the test can precisely control when the server-side handler is allowed to finish.
  • Add bounded waits/timeouts around both “request reached server” and runloop execution to avoid hanging.

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

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 TestSendRequestAsyncAndCloseClientOnHandle

1 participant