Add test for channel send failure after receiver drop#351
Conversation
|
Warning Rate limit exceeded@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 53 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughAdd a new async test validating that sending on an mpsc channel fails after the receiver is dropped. No production code changes; only a test addition in tests/multi_packet.rs. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Comment |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR adds a regression test to verify that sending on an mpsc channel fails once the receiver is dropped. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
tests/multi_packet.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
⚙️ CodeRabbit configuration file
**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.
Adhere to single responsibility and CQRS
Place function attributes after doc comments.
Do not use
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless absolutely necessary.Every module must begin with a
//!doc comment that explains the module's purpose and utility.Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar
Lints must not be silenced except as a last resort.
#[allow]is forbidden.- Only narrowly scoped
#[expect(lint, reason = "...")]is allowed.- No lint groups, no blanket or file-wide suppression.
- Include
FIXME:with link if a fix is expected.Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.
Use
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor mocks/stubs.Prefer
.expect()over.unwrap()Ensure that any API or behavioural changes are reflected in the documentation in
docs/Ensure that any completed roadmap steps are recorded in the appropriate roadmap in
docs/Files must not exceed 400 lines in length
- Large modules must be decomposed
- Long match statements or dispatch tables should be decomposed by domain and collocated with targets
- Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such
- For testing of functionality depending upon environment variables, dependency injection and the
mockablecrate are the preferred option.- If mockable cannot be used, env mutations in tests ...
Files:
tests/multi_packet.rs
🔍 Remote MCP
Here are a few points from Tokio’s documentation that are directly relevant to the new test in tests/multi_packet.rs:
-
Sending on a bounded
tokio::sync::mpsc::Sender<T>will immediately return an error if the receive half has been closed (i.e. theReceiverhas been dropped orclose()called). In that case,send(value).awaityieldsErr(SendError(value)). -
The error type is
SendError<T>(for the asyncsendmethod) orTrySendError::Closed(for the immediatetry_sendmethod), and in both cases the original value is returned inside the error.
[::turn4search0::] -
Async tests must be annotated with Tokio’s attribute macro
#[tokio::test], which sets up a single-threaded runtime by default so thatasync fntest bodies can.await.
[::turn7search0::]
These facts confirm that the test’s use of
let (tx, rx) = mpsc::channel(2);
drop(rx);
assert_matches!(tx.send(1).await, Err(_));correctly exercises the documented behavior of Tokio’s mpsc channel when the receiver is gone.
🔇 Additional comments (1)
tests/multi_packet.rs (1)
64-71: Assert closed-receiver send behaviour — LGTMValidate that
senderrors after dropping the receiver. Doc comment placement before the attribute matches guidelines.
Summary
mpscsend fails when receiver is dropped before sendTesting
make fmtmake lintmake testhttps://chatgpt.com/codex/tasks/task_e_68bb304382a08322a683fd877a6e49a6
Summary by Sourcery
Tests: