Skip to content

[ISSUE #6165][Test🧪] Add unit tests for QueryTopicsByConsumerRequestHeader#6376

Merged
mxsm merged 4 commits intomxsm:mainfrom
oopscompiled:test/add-test-case-QueryTopicsByConsumerRequestHeader
Feb 18, 2026
Merged

[ISSUE #6165][Test🧪] Add unit tests for QueryTopicsByConsumerRequestHeader#6376
mxsm merged 4 commits intomxsm:mainfrom
oopscompiled:test/add-test-case-QueryTopicsByConsumerRequestHeader

Conversation

@oopscompiled
Copy link
Contributor

@oopscompiled oopscompiled commented Feb 18, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Tests
    • Expanded unit test coverage for query topics by consumer functionality, including serialization/deserialization validation, error handling for malformed inputs, and edge case scenarios.

Copilot AI review requested due to automatic review settings February 18, 2026 13:31
@rocketmq-rust-bot
Copy link
Collaborator

🔊@oopscompiled 🚀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 18, 2026

Walkthrough

Comprehensive unit tests have been added to QueryTopicsByConsumerRequestHeader, covering debug formatting, getter/setter behavior, serialization/deserialization, edge cases, and error handling scenarios. No public API changes.

Changes

Cohort / File(s) Summary
Unit Tests for QueryTopicsByConsumerRequestHeader
rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs
Added 137 lines of tests covering struct creation, getter/setter operations, serde serialization/deserialization with field renaming, flattened rpc_request_header handling, round-trip consistency, edge cases (special characters, long values, empty groups), JSON error handling, and nested field access patterns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

approved

Suggested reviewers

  • mxsm
  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🐰 Hopping through the test code with glee,
QueryTopicsbyConsumer now tested we see,
Serialization, deserialization, edge cases galore,
Coverage expanded, reliability to adore!

🚥 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 clearly summarizes the main change: adding unit tests for QueryTopicsByConsumerRequestHeader, which aligns with the primary changeset focus.
Linked Issues check ✅ Passed The PR comprehensively addresses the linked issue #6165 test scope, implementing unit tests for basic structure, getter/setter behavior, serialization/deserialization, RpcRequestHeader nested access, edge cases, and error handling as specified.
Out of Scope Changes check ✅ Passed All changes are within scope: unit tests for QueryTopicsByConsumerRequestHeader and a related test for GetConsumeStatsRequestHeader, plus minor clippy fixes, all related to the testing objective.
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

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.

@rocketmq-rust-bot rocketmq-rust-bot self-requested a review February 18, 2026 13:32
Copy link
Contributor

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

Adds/expands unit test coverage for RocketMQ remoting protocol request headers, primarily focusing on QueryTopicsByConsumerRequestHeader serialization/deserialization and basic accessor behavior.

Changes:

  • Add a comprehensive suite of unit tests for QueryTopicsByConsumerRequestHeader (debug, getters/setters, serde edge cases).
  • Add new unit tests for GetConsumeStatsRequestHeader (getters/setters and serde round-trip) and remove obsolete commented constants.

Reviewed changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

File Description
rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs Adds multiple unit tests around debug output, getters/setters, serde error cases, and round-trip behavior.
rocketmq-remoting/src/protocol/header/get_consume_stats_request_header.rs Removes commented-out constants and introduces a new test module for header accessors + serde behavior.

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

Comment on lines +237 to +240
use std::mem;
let _sz = mem::size_of::<QueryTopicsByConsumerRequestHeader>();
assert!(_sz > 0);

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

This test asserts size_of::<QueryTopicsByConsumerRequestHeader>() > 0, which is effectively a tautology here and doesn’t validate any observable behavior. Consider removing the size check or replacing it with a meaningful invariant that the code relies on (e.g., serialization/deserialization behavior only).

Suggested change
use std::mem;
let _sz = mem::size_of::<QueryTopicsByConsumerRequestHeader>();
assert!(_sz > 0);

Copilot uses AI. Check for mistakes.
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
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.

🧹 Nitpick comments (3)
rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs (3)

129-134: Test name is misleading — this tests serde's behavior, not the #[required] macro attribute.

#[required] is a custom attribute consumed by the RequestHeaderCodecV2 / FromMap codec, not by serde. What this test actually validates is that serde refuses to deserialize a struct when a non-optional, non-defaulted field (group: CheetahString) is absent. Consider renaming to serde_deserialize_missing_group_field_errors and adding a complementary test that verifies FromMap returns an error when group is absent (exercising the actual #[required] constraint).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs`
around lines 129 - 134, Rename the test
serde_deserialize_missing_required_field_errors to
serde_deserialize_missing_group_field_errors to accurately reflect it verifies
serde refusal to deserialize QueryTopicsByConsumerRequestHeader when the
non-optional field group: CheetahString is missing, and add a new test that
constructs a Map (or uses RequestHeaderCodecV2::from_map / FromMap for
QueryTopicsByConsumerRequestHeader) with the group key omitted and asserts that
FromMap returns an Err to exercise the #[required] attribute enforcement; update
test names and assertions accordingly to keep both serde and codec behaviors
covered.

119-127: Prefer direct public field access over getter/setter methods in tests.

The struct fields group and rpc_request_header are already pub. Testing get_group() / set_group() couples the tests to convenience methods that may be out of pattern with the rest of the codebase. Direct field access better reflects the established convention.

♻️ Suggested alternative
 fn getter_setter_multiple_calls() {
     let mut header = QueryTopicsByConsumerRequestHeader::new("g1");
-    assert_eq!(header.get_group(), "g1");
-    header.set_group(CheetahString::from("g2"));
-    assert_eq!(header.get_group(), "g2");
-    header.set_group(CheetahString::from("g3"));
-    assert_eq!(header.get_group(), "g3");
+    assert_eq!(header.group, "g1");
+    header.group = CheetahString::from("g2");
+    assert_eq!(header.group, "g2");
+    header.group = CheetahString::from("g3");
+    assert_eq!(header.group, "g3");
 }

Based on learnings: header structs in rocketmq-remoting/src/protocol/header/ should consistently use public fields rather than private fields with getters/setters; direct public access is the preferred pattern across this module.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs`
around lines 119 - 127, The test getter_setter_multiple_calls uses the
convenience methods get_group and set_group on
QueryTopicsByConsumerRequestHeader but this module prefers direct public field
access; update the test to read and write header.group directly (e.g.,
assert_eq!(header.group, "g1") and header.group = CheetahString::from("g2")) and
similarly replace subsequent get/set calls with direct assignments and
assertions; ensure any use of rpc_request_header in other tests follows the same
public-field access pattern.

235-246: mem::size_of::<T>() > 0 is a trivially-true no-op assertion.

Any non-ZST Rust type has a non-zero size. This assertion never catches a real regression. Either remove the _sz check or replace it with a stronger structural invariant (e.g., minimum expected size).

♻️ Suggested simplification
 fn struct_size_check_and_empty_group_behavior() {
-    use std::mem;
-    let _sz = mem::size_of::<QueryTopicsByConsumerRequestHeader>();
-    assert!(_sz > 0);
-
     let header_empty = QueryTopicsByConsumerRequestHeader::new("");
     let json = serde_json::to_string(&header_empty).unwrap();
     assert!(json.contains("\"group\":\"\""));
     let header2: QueryTopicsByConsumerRequestHeader = serde_json::from_str(&json).unwrap();
     assert_eq!(header2.group, "");
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs`
around lines 235 - 246, The test struct_size_check_and_empty_group_behavior
contains a meaningless assertion using
mem::size_of::<QueryTopicsByConsumerRequestHeader>() > 0; remove that no-op
assertion (or replace it with a concrete expected-size check if you want a real
invariant) and keep the rest of the test (creating
QueryTopicsByConsumerRequestHeader::new(""), serializing to JSON, asserting it
contains "\"group\":\"\"", and round-tripping via serde to assert header2.group
== ""); update the test to either drop the _sz variable entirely or change it to
assert_eq!(mem::size_of::<QueryTopicsByConsumerRequestHeader>(),
<expected_size>) if you have a specific expected byte size in mind.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs`:
- Around line 129-134: Rename the test
serde_deserialize_missing_required_field_errors to
serde_deserialize_missing_group_field_errors to accurately reflect it verifies
serde refusal to deserialize QueryTopicsByConsumerRequestHeader when the
non-optional field group: CheetahString is missing, and add a new test that
constructs a Map (or uses RequestHeaderCodecV2::from_map / FromMap for
QueryTopicsByConsumerRequestHeader) with the group key omitted and asserts that
FromMap returns an Err to exercise the #[required] attribute enforcement; update
test names and assertions accordingly to keep both serde and codec behaviors
covered.
- Around line 119-127: The test getter_setter_multiple_calls uses the
convenience methods get_group and set_group on
QueryTopicsByConsumerRequestHeader but this module prefers direct public field
access; update the test to read and write header.group directly (e.g.,
assert_eq!(header.group, "g1") and header.group = CheetahString::from("g2")) and
similarly replace subsequent get/set calls with direct assignments and
assertions; ensure any use of rpc_request_header in other tests follows the same
public-field access pattern.
- Around line 235-246: The test struct_size_check_and_empty_group_behavior
contains a meaningless assertion using
mem::size_of::<QueryTopicsByConsumerRequestHeader>() > 0; remove that no-op
assertion (or replace it with a concrete expected-size check if you want a real
invariant) and keep the rest of the test (creating
QueryTopicsByConsumerRequestHeader::new(""), serializing to JSON, asserting it
contains "\"group\":\"\"", and round-tripping via serde to assert header2.group
== ""); update the test to either drop the _sz variable entirely or change it to
assert_eq!(mem::size_of::<QueryTopicsByConsumerRequestHeader>(),
<expected_size>) if you have a specific expected byte size in mind.

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6376      +/-   ##
==========================================
+ Coverage   42.42%   42.46%   +0.04%     
==========================================
  Files         921      921              
  Lines      129596   129703     +107     
==========================================
+ Hits        54980    55079      +99     
- Misses      74616    74624       +8     

☔ 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
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 8c801c3 into mxsm:main Feb 18, 2026
10 of 14 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 18, 2026
@oopscompiled oopscompiled deleted the test/add-test-case-QueryTopicsByConsumerRequestHeader branch February 18, 2026 14:13
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 QueryTopicsByConsumerRequestHeader

4 participants

Comments