Skip to content

[ISSUE #6210][Test🧪] Add unit tests for OffsetMovedEvent#6319

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

[ISSUE #6210][Test🧪] Add unit tests for OffsetMovedEvent#6319
mxsm merged 4 commits intomxsm:mainfrom
oopscompiled:test/add-test-case-OffsetMovedEvent

Conversation

@oopscompiled
Copy link
Contributor

@oopscompiled oopscompiled commented Feb 13, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests validating offset event handling, accessors, display formatting, and JSON serialization/deserialization to improve reliability of offset-related behavior.

Copilot AI review requested due to automatic review settings February 13, 2026 19:46
@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 13, 2026

Walkthrough

Added a unit test module for OffsetMovedEvent in the remoting protocol, introducing JSON (de)serialization, Display formatting, getter/setter, and round-trip tests; no production API or logic changes.

Changes

Cohort / File(s) Summary
OffsetMovedEvent Unit Tests
rocketmq-remoting/src/protocol/topic.rs
Added ~86 lines of unit tests covering field initialization, getters/setters, Display formatting, JSON serialization/deserialization, and round-trip checks for OffsetMovedEvent.
Manifest
Cargo.toml
Updated manifest metadata (lines changed: +88) accompanying the test additions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 I hopped through code with nimble feet,

Tests now guard each offset beat.
JSON, Display, getters too—
A gentle hop, the checks pass through.

🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (173 files):

⚔️ .clippy.toml (content)
⚔️ .coderabbit.yaml (content)
⚔️ .github/workflows/dashboard-tauri-ci.yml (content)
⚔️ .github/workflows/deploy.yml (content)
⚔️ CHANGELOG.md (content)
⚔️ Cargo.lock (content)
⚔️ Cargo.toml (content)
⚔️ distribution/config/broker/1m-1s-async-one-machine/broker-master.toml (content)
⚔️ distribution/config/broker/1m-1s-async-one-machine/broker-slave.toml (content)
⚔️ distribution/config/broker/2m-2s-async/broker-a-master.toml (content)
⚔️ distribution/config/broker/2m-2s-async/broker-a-slave.toml (content)
⚔️ distribution/config/broker/2m-2s-async/broker-b-master.toml (content)
⚔️ distribution/config/broker/2m-2s-async/broker-b-slave.toml (content)
⚔️ distribution/config/broker/broker-simple-master.toml (content)
⚔️ distribution/config/broker/broker-simple-slave.toml (content)
⚔️ distribution/config/broker/broker.toml (content)
⚔️ distribution/config/nameserver/namesrv.toml (content)
⚔️ rocketmq-auth/Cargo.toml (content)
⚔️ rocketmq-auth/src/authentication/strategy.rs (content)
⚔️ rocketmq-auth/src/authorization/metadata_provider/local.rs (content)
⚔️ rocketmq-auth/src/authorization/model/acl.rs (content)
⚔️ rocketmq-auth/src/authorization/model/environment.rs (content)
⚔️ rocketmq-auth/src/authorization/model/policy.rs (content)
⚔️ rocketmq-auth/src/authorization/model/policy_entry.rs (content)
⚔️ rocketmq-auth/src/authorization/model/resource.rs (content)
⚔️ rocketmq-broker/Cargo.toml (content)
⚔️ rocketmq-broker/src/broker_runtime.rs (content)
⚔️ rocketmq-broker/src/client/consumer_group_info.rs (content)
⚔️ rocketmq-broker/src/long_polling/many_pull_request.rs (content)
⚔️ rocketmq-broker/src/processor.rs (content)
⚔️ rocketmq-broker/src/processor/consumer_manage_processor.rs (content)
⚔️ rocketmq-broker/src/processor/notification_processor.rs (content)
⚔️ rocketmq-broker/src/processor/pop_message_processor.rs (content)
⚔️ rocketmq-broker/src/processor/send_message_processor.rs (content)
⚔️ rocketmq-broker/src/topic/manager/topic_config_manager.rs (content)
⚔️ rocketmq-client/Cargo.toml (content)
⚔️ rocketmq-client/README.md (content)
⚔️ rocketmq-client/benches/thread_local_index_bench.rs (content)
⚔️ rocketmq-client/examples/broadcast/push_consumer.rs (content)
⚔️ rocketmq-client/examples/consumer/pop_consumer.rs (content)
⚔️ rocketmq-client/examples/ordermessage/ordermessage_consumer.rs (content)
⚔️ rocketmq-client/examples/quickstart/consumer.rs (content)
⚔️ rocketmq-client/src/admin/default_mq_admin_ext_impl.rs (content)
⚔️ rocketmq-client/src/base.rs (content)
⚔️ rocketmq-client/src/base/client_config.rs (content)
⚔️ rocketmq-client/src/common/thread_local_index.rs (content)
⚔️ rocketmq-client/src/consumer/consumer_impl/pull_api_wrapper.rs (content)
⚔️ rocketmq-client/src/consumer/default_mq_push_consumer.rs (content)
⚔️ rocketmq-client/src/consumer/default_mq_push_consumer_builder.rs (content)
⚔️ rocketmq-client/src/consumer/mq_push_consumer.rs (content)
⚔️ rocketmq-client/src/consumer/rebalance_strategy/allocate_message_queue_by_machine_room_nearby.rs (content)
⚔️ rocketmq-client/src/implementation/mq_client_api_impl.rs (content)
⚔️ rocketmq-client/src/producer.rs (content)
⚔️ rocketmq-client/src/producer/default_mq_produce_builder.rs (content)
⚔️ rocketmq-client/src/producer/default_mq_producer.rs (content)
⚔️ rocketmq-client/src/producer/mq_producer.rs (content)
⚔️ rocketmq-client/src/producer/producer_impl.rs (content)
⚔️ rocketmq-client/src/producer/producer_impl/default_mq_producer_impl.rs (content)
⚔️ rocketmq-client/src/producer/transaction_mq_producer.rs (content)
⚔️ rocketmq-client/tests/thread_local_index_test.rs (content)
⚔️ rocketmq-common/Cargo.toml (content)
⚔️ rocketmq-common/src/common.rs (content)
⚔️ rocketmq-common/src/common/broker/broker_config.rs (content)
⚔️ rocketmq-common/src/common/config_manager.rs (content)
⚔️ rocketmq-common/src/common/message.rs (content)
⚔️ rocketmq-common/src/common/topic.rs (content)
⚔️ rocketmq-common/src/lib.rs (content)
⚔️ rocketmq-common/src/utils/http_tiny_client.rs (content)
⚔️ rocketmq-controller/Cargo.toml (content)
⚔️ rocketmq-controller/examples/controller.toml (content)
⚔️ rocketmq-controller/src/cli.rs (content)
⚔️ rocketmq-controller/src/processor.rs (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-common/Cargo.toml (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-gpui/Cargo.lock (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-gpui/Cargo.toml (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-tauri/README.md (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-tauri/package-lock.json (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-tauri/package.json (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-tauri/src-tauri/Cargo.lock (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-tauri/src-tauri/Cargo.toml (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-tauri/src-tauri/src/lib.rs (content)
⚔️ rocketmq-dashboard/rocketmq-dashboard-tauri/src/pages/Login.tsx (content)
⚔️ rocketmq-doc/README.md (content)
⚔️ rocketmq-error/Cargo.toml (content)
⚔️ rocketmq-example/Cargo.lock (content)
⚔️ rocketmq-example/Cargo.toml (content)
⚔️ rocketmq-example/examples/consumer/pop_consumer.rs (content)
⚔️ rocketmq-filter/Cargo.toml (content)
⚔️ rocketmq-macros/Cargo.toml (content)
⚔️ rocketmq-namesrv/Cargo.toml (content)
⚔️ rocketmq-namesrv/resource/namesrv-example.toml (content)
⚔️ rocketmq-namesrv/resource/namesrv.toml (content)
⚔️ rocketmq-namesrv/src/route/route_info_manager.rs (content)
⚔️ rocketmq-namesrv/src/route/tables/topic_queue_mapping_table.rs (content)
⚔️ rocketmq-namesrv/src/route/types.rs (content)
⚔️ rocketmq-proxy/Cargo.toml (content)
⚔️ rocketmq-remoting/Cargo.toml (content)
⚔️ rocketmq-remoting/src/clients/rocketmq_tokio_client.rs (content)
⚔️ rocketmq-remoting/src/code.rs (content)
⚔️ rocketmq-remoting/src/code/request_code.rs (content)
⚔️ rocketmq-remoting/src/lib.rs (content)
⚔️ rocketmq-remoting/src/protocol.rs (content)
⚔️ rocketmq-remoting/src/protocol/admin/consume_stats.rs (content)
⚔️ rocketmq-remoting/src/protocol/admin/consume_stats_list.rs (content)
⚔️ rocketmq-remoting/src/protocol/admin/topic_stats_table.rs (content)
⚔️ rocketmq-remoting/src/protocol/body.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/broker_body/register_broker_body.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/broker_replicas_info.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/check_client_request_body.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/process_queue_info.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/queue_time_span.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/timer_metrics_serialize_wrapper.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/topic_info_wrapper/topic_config_wrapper.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/topic_info_wrapper/topic_queue_wrapper.rs (content)
⚔️ rocketmq-remoting/src/protocol/body/unlock_batch_request_body.rs (content)
⚔️ rocketmq-remoting/src/protocol/header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/empty_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/get_consumer_connection_list_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/get_consumer_status_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/get_max_offset_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/get_max_offset_response_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/get_min_offset_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/get_topic_config_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/get_topic_stats_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/heartbeat_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/namesrv/broker_request.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/namesrv/perm_broker_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/notification_response_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/notify_broker_role_change_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/notify_consumer_ids_changed_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/query_consumer_offset_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/query_consumer_offset_response_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/header/query_topics_by_consumer_request_header.rs (content)
⚔️ rocketmq-remoting/src/protocol/heartbeat/subscription_data.rs (content)
⚔️ rocketmq-remoting/src/protocol/namespace_util.rs (content)
⚔️ rocketmq-remoting/src/protocol/namesrv.rs (content)
⚔️ rocketmq-remoting/src/protocol/route/topic_route_data.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic/logic_queue_mapping_item.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic/topic_config_and_queue_mapping.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic/topic_queue_mapping_context.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic/topic_queue_mapping_detail.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic/topic_queue_mapping_one.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic/topic_queue_mapping_utils.rs (content)
⚔️ rocketmq-remoting/src/protocol/static_topic/topic_remapping_detail_wrapper.rs (content)
⚔️ rocketmq-remoting/src/protocol/subscription/broker_stats_data.rs (content)
⚔️ rocketmq-remoting/src/protocol/subscription/group_retry_policy.rs (content)
⚔️ rocketmq-remoting/src/protocol/subscription/simple_subscription_data.rs (content)
⚔️ rocketmq-remoting/src/protocol/topic.rs (content)
⚔️ rocketmq-remoting/src/rpc/client_metadata.rs (content)
⚔️ rocketmq-runtime/Cargo.toml (content)
⚔️ rocketmq-store/Cargo.toml (content)
⚔️ rocketmq-store/src/utils/ffi.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-cli/Cargo.toml (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/Cargo.toml (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/admin/default_mq_admin_ext.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/admin/mq_admin_utils.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/cli/commands.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/auth_commands.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/command_util.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/consumer_commands.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/topic_commands/topic_status_sub_command.rs (content)
⚔️ rocketmq-tools/rocketmq-admin/rocketmq-admin-tui/Cargo.toml (content)
⚔️ rocketmq-tools/rocketmq-store-inspect/Cargo.toml (content)
⚔️ rocketmq-website/PROJECT_STRUCTURE.md (content)
⚔️ rocketmq-website/PROJECT_STRUCTURE_zh-CN.md (content)
⚔️ rocketmq-website/README.md (content)
⚔️ rocketmq-website/package.json (content)
⚔️ rocketmq-website/releases/authors.yml (content)
⚔️ rocketmq/Cargo.toml (content)
⚔️ rust-toolchain.toml (content)
⚔️ rustfmt.toml (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ 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 OffsetMovedEvent in the specified file, with appropriate issue reference and test emoji label.
Linked Issues check ✅ Passed The PR implements most test scenarios from #6210 including field initialization, JSON serialization/deserialization, roundtrip testing, and MessageQueue field testing, addressing core coding requirements effectively.
Out of Scope Changes check ✅ Passed All changes are focused solely on adding test coverage for OffsetMovedEvent with no modifications to production code or unrelated logic, staying entirely within the scope of issue #6210.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% 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
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch test/add-test-case-OffsetMovedEvent
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉


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: 2

🤖 Fix all issues with AI agents
In `@rocketmq-remoting/src/protocol/topic.rs`:
- Line 90: Rename the test function offest_moved_event_setters to
offset_moved_event_setters; update the fn declaration and any references to that
identifier (uses, test annotations like #[test], or module-level refs) so the
test name is spelled correctly and remains discoverable by the test runner.
- Around line 133-144: The test offset_moved_event_serialise for
OffsetMovedEvent only asserts consumer_group/offset fields and misses verifying
message_queue; update the test (offset_moved_event_serialise) to also assert
that the serialized json contains the message_queue key (e.g.
assert!(json.contains("\"message_queue\":")) or compare against a full expected
JSON string matching the serialization of MessageQueue::new()), so MessageQueue
serialization is validated alongside consumer_group and offsets.
🧹 Nitpick comments (1)
rocketmq-remoting/src/protocol/topic.rs (1)

71-155: Missing required OffsetMovedEvent test cases from issue #6210.

The current suite doesn’t cover several explicit requirements: message_queue setter/field behavior, serde round‑trip, Debug/Clone (if derived), and negative/zero/large offset values. Please add these to meet the stated objectives and reach the target coverage.

Comment on lines 133 to 144
fn offset_moved_event_serialise() {
let body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
let json = serde_json::to_string(&body).unwrap();
assert!(json.contains("\"consumer_group\":\"test_group\""));
assert!(json.contains("\"offset_request\":100"));
assert!(json.contains("\"offset_new\":200"));
}
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 | 🟡 Minor

Serialization test doesn’t validate message_queue.

You only assert consumer_group/offset fields. Add an assertion that the serialized JSON includes message_queue (or compare against a full expected JSON) to ensure it’s included.

🤖 Prompt for AI Agents
In `@rocketmq-remoting/src/protocol/topic.rs` around lines 133 - 144, The test
offset_moved_event_serialise for OffsetMovedEvent only asserts
consumer_group/offset fields and misses verifying message_queue; update the test
(offset_moved_event_serialise) to also assert that the serialized json contains
the message_queue key (e.g. assert!(json.contains("\"message_queue\":")) or
compare against a full expected JSON string matching the serialization of
MessageQueue::new()), so MessageQueue serialization is validated alongside
consumer_group and offsets.

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

This pull request adds unit tests for the OffsetMovedEvent struct in the rocketmq-remoting module to address issue #6210. The PR adds basic test coverage for field initialization, getters, setters, Display trait implementation, and JSON serialization/deserialization.

Changes:

  • Added 6 unit tests for OffsetMovedEvent covering initialization, getters, setters, Display formatting, serialization, and deserialization
  • Tests verify basic functionality of the struct's methods and trait implementations
  • Includes JSON serialization/deserialization validation

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

}

#[test]
fn offest_moved_event_setters() {
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Typo in test function name: "offest_moved_event_setters" should be "offset_moved_event_setters". This misspelling makes the test name inconsistent with other test names in the file and harder to find.

Suggested change
fn offest_moved_event_setters() {
fn offset_moved_event_setters() {

Copilot uses AI. Check for mistakes.
Comment on lines 71 to 155
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn offset_moved_event_init() {
let body: OffsetMovedEvent = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
assert_eq!(body.get_consumer_group(), "test_group");
assert_eq!(body.get_offset_request(), 100);
assert_eq!(body.get_offset_new(), 200);
assert_eq!(body.get_message_queue(), &MessageQueue::new());
}

#[test]
fn offest_moved_event_setters() {
let mut body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
body.set_consumer_group("new_group".to_string());
body.set_offset_request(150);
body.set_offset_new(250);
assert_eq!(body.get_consumer_group(), "new_group");
assert_eq!(body.get_offset_request(), 150);
assert_eq!(body.get_offset_new(), 250);
}

#[test]
fn offset_moved_event_getters() {
let body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
assert_eq!(body.get_consumer_group(), "test_group");
assert_eq!(body.get_offset_request(), 100);
assert_eq!(body.get_offset_new(), 200);
}

#[test]
fn offset_moved_event_display() {
let body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
let display = format!("{}", body);
assert!(display.contains("OffsetMovedEvent"));
assert!(display.contains("consumer_group=test_group"));
assert!(display.contains("offset_request=100"));
assert!(display.contains("offset_new=200"));
}
#[test]
fn offset_moved_event_serialise() {
let body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
let json = serde_json::to_string(&body).unwrap();
assert!(json.contains("\"consumer_group\":\"test_group\""));
assert!(json.contains("\"offset_request\":100"));
assert!(json.contains("\"offset_new\":200"));
}

#[test]
fn offset_moved_event_deserialise() {
let json = r#"{"consumer_group":"test_group","message_queue":{"topic":"","brokerName":"","queueId":0},"offset_request":100,"offset_new":200}"#;
let body: OffsetMovedEvent = serde_json::from_str(json).unwrap();
assert_eq!(body.get_consumer_group(), "test_group");
assert_eq!(body.get_offset_request(), 100);
assert_eq!(body.get_offset_new(), 200);
assert_eq!(body.get_message_queue(), &MessageQueue::new());
}
}
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The test coverage is incomplete based on the requirements in issue #6210. The following test cases are missing:

  1. Test with negative offset values
  2. Test with zero offset values
  3. Test with large offset values
  4. Test serialization/deserialization roundtrip
  5. Test Clone trait implementation (note: Clone is not currently derived on OffsetMovedEvent, so it cannot be cloned)

Consider adding tests for edge cases with negative, zero, and large offset values. Additionally, add a roundtrip test that serializes and then deserializes to ensure data integrity. If Clone trait is needed, add it to the struct's derive macro first.

Copilot uses AI. Check for mistakes.
Comment on lines 76 to 155
fn offset_moved_event_init() {
let body: OffsetMovedEvent = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
assert_eq!(body.get_consumer_group(), "test_group");
assert_eq!(body.get_offset_request(), 100);
assert_eq!(body.get_offset_new(), 200);
assert_eq!(body.get_message_queue(), &MessageQueue::new());
}

#[test]
fn offest_moved_event_setters() {
let mut body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
body.set_consumer_group("new_group".to_string());
body.set_offset_request(150);
body.set_offset_new(250);
assert_eq!(body.get_consumer_group(), "new_group");
assert_eq!(body.get_offset_request(), 150);
assert_eq!(body.get_offset_new(), 250);
}

#[test]
fn offset_moved_event_getters() {
let body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
assert_eq!(body.get_consumer_group(), "test_group");
assert_eq!(body.get_offset_request(), 100);
assert_eq!(body.get_offset_new(), 200);
}

#[test]
fn offset_moved_event_display() {
let body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
let display = format!("{}", body);
assert!(display.contains("OffsetMovedEvent"));
assert!(display.contains("consumer_group=test_group"));
assert!(display.contains("offset_request=100"));
assert!(display.contains("offset_new=200"));
}
#[test]
fn offset_moved_event_serialise() {
let body = OffsetMovedEvent {
consumer_group: "test_group".to_string(),
message_queue: MessageQueue::new(),
offset_request: 100,
offset_new: 200,
};
let json = serde_json::to_string(&body).unwrap();
assert!(json.contains("\"consumer_group\":\"test_group\""));
assert!(json.contains("\"offset_request\":100"));
assert!(json.contains("\"offset_new\":200"));
}

#[test]
fn offset_moved_event_deserialise() {
let json = r#"{"consumer_group":"test_group","message_queue":{"topic":"","brokerName":"","queueId":0},"offset_request":100,"offset_new":200}"#;
let body: OffsetMovedEvent = serde_json::from_str(json).unwrap();
assert_eq!(body.get_consumer_group(), "test_group");
assert_eq!(body.get_offset_request(), 100);
assert_eq!(body.get_offset_new(), 200);
assert_eq!(body.get_message_queue(), &MessageQueue::new());
}
}
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The test naming pattern is inconsistent with conventions found in similar test files in this codebase. For example, in protocol/admin/topic_offset.rs and protocol/admin/rollback_stats.rs, test names use underscores to separate words and typically follow patterns like test_<module>_<behavior> or <module>_<behavior>.

Consider renaming tests to follow a more consistent pattern:

  • offset_moved_event_initoffset_moved_event_field_initialization or similar
  • offset_moved_event_serialiseoffset_moved_event_serialization
  • offset_moved_event_deserialiseoffset_moved_event_deserialization

Using the full "serialization" and "deserialization" spelling aligns better with other test files in the codebase.

Copilot uses AI. Check for mistakes.
oopscompiled and others added 2 commits February 13, 2026 20:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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 ✅

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.56%. Comparing base (58344a5) to head (ede959f).
⚠️ Report is 95 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6319      +/-   ##
==========================================
+ Coverage   40.55%   42.56%   +2.01%     
==========================================
  Files         886      911      +25     
  Lines      122833   127899    +5066     
==========================================
+ Hits        49810    54446    +4636     
- Misses      73023    73453     +430     

☔ 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.

@mxsm mxsm merged commit 387f478 into mxsm:main Feb 14, 2026
10 of 12 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 14, 2026
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 OffsetMovedEvent

5 participants