Skip to content

Add unit tests for HeartbeatRequestHeader#6234

Merged
mxsm merged 1 commit intomxsm:mainfrom
willwang-io:issue-6218
Feb 9, 2026
Merged

Add unit tests for HeartbeatRequestHeader#6234
mxsm merged 1 commit intomxsm:mainfrom
willwang-io:issue-6218

Conversation

@willwang-io
Copy link
Contributor

@willwang-io willwang-io commented Feb 8, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

Implement 22 comprehensive test cases covering:

  • Default and Debug trait implementations
  • JSON serialization/deserialization with camelCase fields
  • Roundtrip serialization with None, Some, and partial fields
  • Flattened serde attribute behavior
  • RequestHeaderCodecV2 macro-generated FromMap trait
  • Individual RpcRequestHeader field validation

These tests ensure the header correctly serializes to JSON with flattened RpcRequestHeader fields at the top level, properly handles optional nested structures, and maintains compatibility with the protocol's camelCase naming convention.

How Did You Test This Change?

  • All 22 tests passes successfully
  • cargo fmt --all -- --check
  • cargo test --all-features --workspace
  • cargo clippy --all-targets --all-features --workspace

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for heartbeat request handling with comprehensive cases for initialization, serialization/deserialization, round-trips, debug/display, and field accessors.
    • Tests-only changes; public API remains unchanged.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@willwang-io 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

Walkthrough

Adds a comprehensive test module for HeartbeatRequestHeader covering default initialization, JSON (camelCase) serialization/deserialization, roundtrips, handling of optional rpc_request, FromMap integration, Debug/Display checks, and nested RpcRequestHeader field accessors.

Changes

Cohort / File(s) Summary
HeartbeatRequestHeader tests
rocketmq-remoting/src/protocol/header/heartbeat_request_header.rs
Added ~364 lines of tests exercising: Default, Debug/Display, JSON serialization/deserialization with camelCase, serialization/deserialization roundtrips, handling None/Some for flattened rpc_request, FromMap integration, and field-level accessors for nested RpcRequestHeader.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through bytes and JSON light,

testing heartbeats through day and night,
Optional rpc tucked snug inside,
Roundtrips checked with cautious pride,
A rabbit's nod — the tests run bright.

🚥 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 'Add unit tests for HeartbeatRequestHeader' accurately and concisely summarizes the primary change in the pull request, which adds 22 unit tests for the HeartbeatRequestHeader type.
Linked Issues check ✅ Passed The pull request implements all required test scenarios from issue #6218: default initialization, JSON serialization/deserialization with camelCase, roundtrip tests, None/Some rpc_request handling, flattened serde attribute verification, RequestHeaderCodecV2 macro behavior, Debug/Default traits, and nested RpcRequestHeader testing.
Out of Scope Changes check ✅ Passed All changes are confined to a new test module in heartbeat_request_header.rs; no modifications to public API or unrelated code, keeping the PR focused on the stated objective of improving test coverage.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

🧹 Recent nitpick comments
rocketmq-remoting/src/protocol/header/heartbeat_request_header.rs (1)

196-241: FromMap tests look good — consider adding an unknown-key test.

The empty-map and populated-map cases are well covered. One optional addition: a test with an unrecognized key in the map (e.g., "unknownField") to verify that FromMap gracefully ignores it without error. This would strengthen confidence in forward-compatibility.


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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@rocketmq-remoting/src/protocol/header/heartbeat_request_header.rs`:
- Around line 96-98: Replace clippy-flagged equality-to-bool assertions in this
file by converting assert_eq!(expr, true) to assert!(expr) and assert_eq!(expr,
false) to assert!(!expr); specifically update the assertions referencing
rpc.namespaced, rpc.oneway and any other assert_eq! calls comparing to
true/false (also present elsewhere in the file at the other occurrences
mentioned) so they use assert! or assert!(!) respectively to satisfy the
bool_assert_comparison lint.
🧹 Nitpick comments (2)
rocketmq-remoting/src/protocol/header/heartbeat_request_header.rs (2)

116-128: Roundtrip with None isn't truly a roundtrip — consider noting this explicitly.

Serializing None produces {}, but deserializing {} yields Some(...) due to the flatten behavior. The test already documents this, but the test name roundtrip_with_none is slightly misleading since the value doesn't survive the roundtrip unchanged. Consider renaming to something like roundtrip_with_none_becomes_some_due_to_flatten.


304-389: Consider consolidating individual field tests using a parameterized helper.

The four per-field tests (lines 304–368) and the camelCase test (lines 370–389) each construct nearly identical HeartbeatRequestHeader values. A small helper or macro could reduce boilerplate while retaining coverage.

Comment on lines 96 to 98
assert_eq!(rpc.namespaced.unwrap(), true);
assert_eq!(rpc.broker_name.unwrap(), "test_broker");
assert_eq!(rpc.oneway.unwrap(), false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix clippy bool_assert_comparison errors — CI is failing.

Replace assert_eq!(..., true) with assert!(...) and assert_eq!(..., false) with assert!(!...) across all affected lines. This is flagged by clippy and blocks CI.

🔧 Proposed fix (showing all affected lines)
-        assert_eq!(rpc.namespaced.unwrap(), true);
+        assert!(rpc.namespaced.unwrap());
         assert_eq!(rpc.broker_name.unwrap(), "test_broker");
-        assert_eq!(rpc.oneway.unwrap(), false);
+        assert!(!rpc.oneway.unwrap());
-        assert_eq!(rpc.namespaced.unwrap(), true);
+        assert!(rpc.namespaced.unwrap());
         assert_eq!(rpc.broker_name.unwrap(), "test_broker");
-        assert_eq!(rpc.oneway.unwrap(), false);
+        assert!(!rpc.oneway.unwrap());
-        assert_eq!(rpc.namespaced.unwrap(), true);
+        assert!(rpc.namespaced.unwrap());
         assert_eq!(rpc.broker_name.unwrap(), "test_broker");
-        assert_eq!(rpc.oneway.unwrap(), false);
+        assert!(!rpc.oneway.unwrap());
-        assert_eq!(rpc.namespaced.unwrap(), true);
+        assert!(rpc.namespaced.unwrap());
         assert_eq!(rpc.broker_name.unwrap(), "broker-master");
-        assert_eq!(rpc.oneway.unwrap(), false);
+        assert!(!rpc.oneway.unwrap());
-        assert_eq!(header.rpc_request.as_ref().unwrap().namespaced.unwrap(), true);
+        assert!(header.rpc_request.as_ref().unwrap().namespaced.unwrap());
-        assert_eq!(header.rpc_request.as_ref().unwrap().oneway.unwrap(), true);
+        assert!(header.rpc_request.as_ref().unwrap().oneway.unwrap());

Also applies to: 146-148, 223-225, 299-301, 334-334, 367-367

🧰 Tools
🪛 GitHub Actions: RocketMQ Rust CI

[error] 96-96: clippy: bool_assert_comparison - use 'assert!' instead of 'assert_eq!(..., true)'.


[error] 98-98: clippy: bool_assert_comparison - use 'assert!' instead of 'assert_eq!(..., false)'.

🤖 Prompt for AI Agents
In `@rocketmq-remoting/src/protocol/header/heartbeat_request_header.rs` around
lines 96 - 98, Replace clippy-flagged equality-to-bool assertions in this file
by converting assert_eq!(expr, true) to assert!(expr) and assert_eq!(expr,
false) to assert!(!expr); specifically update the assertions referencing
rpc.namespaced, rpc.oneway and any other assert_eq! calls comparing to
true/false (also present elsewhere in the file at the other occurrences
mentioned) so they use assert! or assert!(!) respectively to satisfy the
bool_assert_comparison lint.

- Default and Debug trait implementations
- JSON serialization/deserialization with camelCase fields
- Roundtrip serialization with None, Some, and partial fields
- Flattened serde attribute behavior
- RequestHeaderCodecV2 macro-generated FromMap trait
- Individual RpcRequestHeader field validation

These tests ensure the header correctly serializes to JSON with
flattened RpcRequestHeader fields at the top level, properly
handles optional nested structures, and maintains compatibility
with the protocol's camelCase naming convention.
@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.85%. Comparing base (6ecc063) to head (fb96d46).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6234      +/-   ##
==========================================
+ Coverage   41.72%   41.85%   +0.12%     
==========================================
  Files         896      896              
  Lines      124905   125180     +275     
==========================================
+ Hits        52115    52391     +276     
+ Misses      72790    72789       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - All CI checks passed ✅

Copy link
Owner

@mxsm mxsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mxsm mxsm merged commit bda4d4e into mxsm:main Feb 9, 2026
10 of 13 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Feb 9, 2026
@willwang-io willwang-io deleted the issue-6218 branch February 9, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Test🧪] Add unit tests for HeartbeatRequestHeader

4 participants