-
Notifications
You must be signed in to change notification settings - Fork 0
Fix processor usage in routes test #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideRefactors the routes test to instantiate and reuse a File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
WalkthroughThe test function in Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @leynos - I've reviewed your changes - here's some feedback:
- Extract the LengthPrefixedProcessor::default() call into a single local variable and clone or reference it when configuring the app, encoding, and decoding to avoid repeating default instantiation.
- Consider moving the processor initialization into a small helper or fixture to reduce boilerplate and keep the test focused on routing logic rather than setup.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract the LengthPrefixedProcessor::default() call into a single local variable and clone or reference it when configuring the app, encoding, and decoding to avoid repeating default instantiation.
- Consider moving the processor initialization into a small helper or fixture to reduce boilerplate and keep the test focused on routing logic rather than setup.
## Individual Comments
### Comment 1
<location> `tests/routes.rs:52` </location>
<code_context>
- LengthPrefixedProcessor
- .encode(&env_bytes, &mut framed)
- .unwrap();
+ let processor = LengthPrefixedProcessor::default();
+ processor.encode(&env_bytes, &mut framed).unwrap();
</code_context>
<issue_to_address>
Consider reusing the processor instance throughout the test for consistency.
Reusing the same processor instance in all test steps, including .frame_processor, helps ensure consistency and can reveal state-related issues if the processor becomes stateful in the future.
Suggested implementation:
```rust
let processor = LengthPrefixedProcessor::default();
let app = app
.frame_processor(processor.clone())
.route(
1,
Box::new(move |_| {
};
let env_bytes = BincodeSerializer.serialize(&env).unwrap();
let mut framed = BytesMut::new();
processor.encode(&env_bytes, &mut framed).unwrap();
let out = run_app_with_frame(app, framed.to_vec()).await.unwrap();
let mut buf = BytesMut::from(&out[..]);
let frame = processor.decode(&mut buf).unwrap().unwrap();
let (resp_env, _) = BincodeSerializer
.deserialize::<TestEnvelope>(&frame)
.unwrap();
```
- Ensure that `LengthPrefixedProcessor` implements `Clone` if it does not already, as `.frame_processor(processor.clone())` requires it.
- If the `app` variable is not defined in this snippet, you may need to adjust the placement of the `processor` instantiation and the `.frame_processor()` call to fit the actual test structure.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
LengthPrefixedProcessor | ||
.encode(&env_bytes, &mut framed) | ||
.unwrap(); | ||
let processor = LengthPrefixedProcessor::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider reusing the processor instance throughout the test for consistency.
Reusing the same processor instance in all test steps, including .frame_processor, helps ensure consistency and can reveal state-related issues if the processor becomes stateful in the future.
Suggested implementation:
let processor = LengthPrefixedProcessor::default();
let app = app
.frame_processor(processor.clone())
.route(
1,
Box::new(move |_| {
};
let env_bytes = BincodeSerializer.serialize(&env).unwrap();
let mut framed = BytesMut::new();
processor.encode(&env_bytes, &mut framed).unwrap();
let out = run_app_with_frame(app, framed.to_vec()).await.unwrap();
let mut buf = BytesMut::from(&out[..]);
let frame = processor.decode(&mut buf).unwrap().unwrap();
let (resp_env, _) = BincodeSerializer
.deserialize::<TestEnvelope>(&frame)
.unwrap();
- Ensure that
LengthPrefixedProcessor
implementsClone
if it does not already, as.frame_processor(processor.clone())
requires it. - If the
app
variable is not defined in this snippet, you may need to adjust the placement of theprocessor
instantiation and the.frame_processor()
call to fit the actual test structure.
Summary
LengthPrefixedProcessor
instead of the struct typeTesting
make fmt
make lint
make test
https://chatgpt.com/codex/tasks/task_e_68558c3a2f608322bcf8739c022f97b1
Summary by Sourcery
Use a default-initialized LengthPrefixedProcessor instance for route configuration and test framing instead of referring to the struct type directly
Tests:
default()
for encode/decode operationsLengthPrefixedProcessor::default()
instance toframe_processor
in app setup instead of the struct typeSummary by CodeRabbit