Skip to content

feat(cpp): add functions related to system#3102

Open
slbotbm wants to merge 2 commits intoapache:masterfrom
slbotbm:cpp-system-functions
Open

feat(cpp): add functions related to system#3102
slbotbm wants to merge 2 commits intoapache:masterfrom
slbotbm:cpp-system-functions

Conversation

@slbotbm
Copy link
Copy Markdown
Contributor

@slbotbm slbotbm commented Apr 12, 2026

Which issue does this PR close?

Works toward completion of #2100

Rationale

This PR adds functions related to the system, and tests for previously untested functions.

What changed?

This PR adds:

  • The following functions and their tests:
    • get_stats
    • get_me
    • get_client
    • get_clients
    • ping
    • heartbeat_interval
    • snapshot

The places labelled TODO will be completed after merging of #3046.

Local Execution

  • Passed
  • Pre-commit hooks ran

AI Usage

If AI tools were used, please answer:

  1. Which tools? (e.g., GitHub Copilot, Claude, ChatGPT) codex
  2. Scope of usage? (e.g., autocomplete, generated functions, entire implementation) code generation based on explicit instructions given by me.
  3. How did you verify the generated code works correctly? ran the tests, read through and understood the generated code
  4. Can you explain every line of the code if asked? yes

@slbotbm slbotbm marked this pull request as draft April 12, 2026 14:29
@slbotbm slbotbm changed the title feata(cpp): add functions related to system, tests for purge_* functions, and consumer group functions (WIP) feat(cpp): add functions related to system, tests for purge_* functions, and consumer group functions (WIP) Apr 12, 2026
@slbotbm slbotbm marked this pull request as ready for review April 22, 2026 11:19
@slbotbm
Copy link
Copy Markdown
Contributor Author

slbotbm commented Apr 22, 2026

This PR is ready for review

@slbotbm slbotbm changed the title feat(cpp): add functions related to system, tests for purge_* functions, and consumer group functions (WIP) feat(cpp): add functions related to system Apr 25, 2026
Comment thread foreign/cpp/src/client.rs Outdated
ffi::ClientInfo {
client_id: client.client_id,
// TODO(slbotbm): In high-level client, this should be converted to None.
user_id: client.user_id.unwrap_or(u32::MAX),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

client.user_id.unwrap_or(u32::MAX) collapses None and a valid id of u32::MAX into the same value. backing type is Option<u32> (core/common/src/types/client/client_info.rs:33). plumb option through ffi - add has_user_id: bool to ffi::ClientInfo or split into a shared cxx option type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added has_user_id

Comment thread foreign/cpp/src/client.rs Outdated
ffi::ClientInfoDetails {
client_id: client.client_id,
// TODO(slbotbm): In high-level client, this should be converted to None.
user_id: client.user_id.unwrap_or(u32::MAX),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same sentinel collision in From<RustClientInfoDetails>. same fix as L40.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread foreign/cpp/src/lib.rs

struct ClientInfo {
client_id: u32,
user_id: u32,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

user_id: u32 in ffi::ClientInfo cannot represent an absent value. root cause behind client.rs:40. add has_user_id: bool field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread foreign/cpp/src/lib.rs

struct ClientInfoDetails {
client_id: u32,
user_id: u32,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same shape problem for ffi::ClientInfoDetails.user_id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread foreign/cpp/src/lib.rs
os_version: String,
kernel_version: String,
iggy_server_version: String,
iggy_server_semver: u32,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

iggy_server_semver: u32 paired with unwrap_or(u32::MAX) sentinel at client.rs:116. backing field is Option<u32> (core/common/src/types/stats/mod.rs:73). prior commit #3036 already got burned by a zero-sentinel - don't repeat. add has_server_semver: bool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

ASSERT_NE(client, nullptr);

const auto heartbeat_interval = client->heartbeat_interval();
EXPECT_EQ(heartbeat_interval, 5'000'000u);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

magic 5'000'000u (and 10'000'000u at L757). define constexpr std::uint64_t kDefaultHeartbeatMicros = 5'000'000ull; or derive from IggyDuration::from("5s").as_micros().

client = nullptr;
}

TEST(LowLevelE2E_Client, SnapshotBeforeLoginThrows) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

all four snapshot tests (L763, L782, L797, L811) are negative paths. add a happy-path test with "deflated" + ["test"] asserting the returned Vec<u8> is non-empty.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

ASSERT_NO_THROW(client->connect());
ASSERT_THROW(client->get_stats(), std::exception);

ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

every test manually does delete_connection(client); client = nullptr;. wrap in struct ScopedClient { ~ScopedClient() { iggy::ffi::delete_connection(p); } }; to cut ~30 lines of boilerplate and recover correctness on test-assertion failure - today the connection leaks if an ASSERT_* aborts mid-test.

ASSERT_NO_THROW({ client = iggy::ffi::new_connection(""); });
ASSERT_NE(client, nullptr);

rust::Vec<rust::String> snapshot_types_before_connect;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rust::Vec<rust::String> snapshot_types; snapshot_types.push_back(...) repeats at L774, L787, L802, L816. add a make_snapshot_types({"test"}) helper in tests/common/test_helpers.hpp.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread foreign/cpp/build.rs Outdated
println!("cargo:rerun-if-changed=src/identifier.rs");
println!("cargo:rerun-if-changed=src/lib.rs");
println!("cargo:rerun-if-changed=src/stream.rs");
println!("cargo:rerun-if-changed=src/system.rs");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cargo:rerun-if-changed=src/system.rs watches a file that doesn't exist (verified ls foreign/cpp/src/system.rs). cargo accepts the entry but it's dead config. delete the line or create the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

deleted line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants