Add timeout handling and refactor connection checks in tests#450
Add timeout handling and refactor connection checks in tests#450
Conversation
…n closure checks Added a helper function `is_connection_closed` to simplify and unify checks for closed connections in the timeout tests. Refactored the tests to use this helper, improving clarity. Also wrapped some socket reads with timeouts for better test reliability. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
Summary by CodeRabbit
WalkthroughState the test changes: add a 1-second timeout around a read in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors preamble timeout tests to use a shared helper for connection-closed detection and wraps key read operations in short timeouts to reduce flakiness and improve reliability, without touching production code. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
is_connection_closedhelper only treatsConnectionResetas a closed-connection error; if your platform/CI sometimes surfaces EOF asConnectionAbortedor similar variants, consider broadening the match to those kinds as well to avoid test flakiness across environments. - The 150ms timeout in
preamble_timeout_allows_timely_preambleis quite tight and may be brittle on slower CI machines; consider relaxing this slightly (e.g., 300–500ms) while still keeping the test meaningfully fast.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `is_connection_closed` helper only treats `ConnectionReset` as a closed-connection error; if your platform/CI sometimes surfaces EOF as `ConnectionAborted` or similar variants, consider broadening the match to those kinds as well to avoid test flakiness across environments.
- The 150ms timeout in `preamble_timeout_allows_timely_preamble` is quite tight and may be brittle on slower CI machines; consider relaxing this slightly (e.g., 300–500ms) while still keeping the test meaningfully fast.
## Individual Comments
### Comment 1
<location> `tests/preamble/timeouts.rs:135` </location>
<code_context>
let mut buf = [0u8; 2];
- stream.read_exact(&mut buf).await?;
+ timeout(Duration::from_millis(150), stream.read_exact(&mut buf)).await??;
let _ = result_tx.send((buf, failure_fired));
Ok(())
</code_context>
<issue_to_address>
**suggestion (testing):** Consider slightly more generous or configurable timeouts to reduce CI flakiness.
150 ms for `read_exact` may be too strict on slow or heavily loaded CI runners, especially with other async work. Consider increasing it (e.g., 300–500 ms) or extracting these values into shared constants so they’re easy to adjust if flakiness shows up.
Suggested implementation:
```rust
let mut buf = [0u8; 2];
})
.is_ok();
const READ_TIMEOUT_MS: u64 = 500;
let mut buf = [0u8; 2];
timeout(Duration::from_millis(READ_TIMEOUT_MS), stream.read_exact(&mut buf)).await??;
let _ = result_tx.send((buf, failure_fired));
Ok(())
})
```
1. If this file (or related test modules) uses similar hardcoded timeouts elsewhere, consider extracting `READ_TIMEOUT_MS` to the module level (outside any function) and reusing it in all relevant places.
2. If you later want per-test configurability (e.g., via env vars for CI vs local), you can replace the `const` with a small helper function that reads from `std::env` with a sensible default, and use that in the `Duration::from_millis(...)` call.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78a4f74635
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Added READ_TIMEOUT_MS constant to standardize timeout duration. - Expanded error matching in is_connection_closed to include ConnectionAborted. - Increased timeout duration for read_exact from 150ms to 500ms to reduce flakiness. These changes improve robustness and clarity of preamble timeout tests. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/preamble/timeouts.rs`:
- Around line 28-46: Replace the remaining hard-coded 500 ms timeout with the
existing READ_TIMEOUT_MS constant to standardize timeouts; find occurrences
(e.g., the other read timeout usage noted in the module) and change the literal
500 (or 500_u64/Duration::from_millis(500)) to use READ_TIMEOUT_MS (or
Duration::from_millis(READ_TIMEOUT_MS)) so the is_connection_closed function and
other reads share the same constant.
|
@coderabbitai Have the following now been resolved? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 5139
Here's the verification:
The code now:
All suggested improvements from the review have been implemented. |
Replaced hardcoded 500ms duration with READ_TIMEOUT_MS constant in the preamble timeout test to improve consistency and maintainability. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
Summary
Changes
Tests
Tests Utilities
Rationale
Test Plan
Impact
◳ Generated by DevBoxer ◰
ℹ️ Tag @devboxerhub to ask questions and address PR feedback
📎 Task: https://www.devboxer.com/task/5b5c7a1b-fa6d-4627-960e-a455ddd02680
Summary by Sourcery
Improve reliability of preamble timeout tests by adding shared connection-closure handling and wrapping test reads in timeouts.
Tests: