Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/health_monitoring_lib/rust/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,94 @@ extern "C" fn health_monitor_destroy(handle: FFIHandle) {
let _ = Box::from_raw(handle as *mut HealthMonitor);
}
}

#[cfg(test)]
mod tests {
use crate::deadline::ffi::{deadline_monitor_builder_create, deadline_monitor_cpp_destroy};
use crate::ffi::{
health_monitor_builder_add_deadline_monitor, health_monitor_builder_build, health_monitor_builder_create,
health_monitor_builder_destroy, health_monitor_destroy, health_monitor_get_deadline_monitor,
health_monitor_start,
};
use crate::IdentTag;

#[test]
fn health_monitor_builder_create_ok() {
let health_monitor_builder_handle = health_monitor_builder_create();
assert!(!health_monitor_builder_handle.is_null());

// Clean-up.
// NOTE: `health_monitor_builder_destroy` positive path is already tested here.
health_monitor_builder_destroy(health_monitor_builder_handle);
}

#[test]
fn health_monitor_builder_add_deadline_monitor_ok() {
let health_monitor_builder_handle = health_monitor_builder_create();
let deadline_monitor_tag = IdentTag::new("deadline_monitor");
let deadline_monitor_builder_handle = deadline_monitor_builder_create();
health_monitor_builder_add_deadline_monitor(
health_monitor_builder_handle,
&deadline_monitor_tag as *const IdentTag,
deadline_monitor_builder_handle,
);

// Clean-up.
health_monitor_builder_destroy(health_monitor_builder_handle);
}

#[test]
fn health_monitor_builder_build_ok() {
let health_monitor_builder_handle = health_monitor_builder_create();
let health_monitor_handle = health_monitor_builder_build(health_monitor_builder_handle, 200, 100);
assert!(!health_monitor_handle.is_null());
Comment on lines +154 to +156
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The build calls repeat magic numbers for cycle durations (e.g., 200 and 100). Consider introducing local constants (e.g., SUPERVISOR_CYCLE_MS, INTERNAL_CYCLE_MS) so the units/intent are clearer and changes only need to be made in one place.

Copilot uses AI. Check for mistakes.

// Clean-up.
// NOTE: `health_monitor_destroy` positive path is already tested here.
health_monitor_destroy(health_monitor_handle);
}

#[test]
fn health_monitor_get_deadline_monitor_ok() {
let health_monitor_builder_handle = health_monitor_builder_create();
let deadline_monitor_tag = IdentTag::new("deadline_monitor");
let deadline_monitor_builder_handle = deadline_monitor_builder_create();
health_monitor_builder_add_deadline_monitor(
health_monitor_builder_handle,
&deadline_monitor_tag as *const IdentTag,
deadline_monitor_builder_handle,
);
let health_monitor_handle = health_monitor_builder_build(health_monitor_builder_handle, 200, 100);

let deadline_monitor_handle =
health_monitor_get_deadline_monitor(health_monitor_handle, &deadline_monitor_tag as *const IdentTag);
assert!(!deadline_monitor_handle.is_null());

// Clean-up.
deadline_monitor_cpp_destroy(deadline_monitor_handle);
health_monitor_destroy(health_monitor_handle);
}

#[test]
fn health_monitor_start_ok() {
let health_monitor_builder_handle = health_monitor_builder_create();
let deadline_monitor_tag = IdentTag::new("deadline_monitor");
let deadline_monitor_builder_handle = deadline_monitor_builder_create();
health_monitor_builder_add_deadline_monitor(
health_monitor_builder_handle,
&deadline_monitor_tag as *const IdentTag,
deadline_monitor_builder_handle,
);
let health_monitor_handle = health_monitor_builder_build(health_monitor_builder_handle, 200, 100);
Comment on lines +186 to +194
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.

These tests repeat the same FFI setup/teardown pattern (create builder, add deadline monitor, build, optionally get deadline monitor). Consider extracting a small helper (or RAII wrapper) to reduce duplication and make cleanup rules for consumed handles harder to get wrong as more cases are added.

Copilot uses AI. Check for mistakes.

let deadline_monitor_handle =
health_monitor_get_deadline_monitor(health_monitor_handle, &deadline_monitor_tag as *const IdentTag);
assert!(!deadline_monitor_handle.is_null());

health_monitor_start(health_monitor_handle);

// Clean-up.
deadline_monitor_cpp_destroy(deadline_monitor_handle);
health_monitor_destroy(health_monitor_handle);
Comment on lines +184 to +204
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

health_monitor_start_ok starts a background thread; the subsequent destroy/join can block for up to internal_cycle_ms because the worker may be sleeping. To keep the unit test suite fast and reduce timing sensitivity, consider using much smaller cycle values here (still respecting the multiple-of invariant).

Copilot uses AI. Check for mistakes.
}
}
Loading