Skip to content

Commit

Permalink
[eclipse-iceoryx#550] Add node death test for notifier death notifica…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
elfenpiff committed Dec 16, 2024
1 parent 903e2bc commit 038d485
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
9 changes: 8 additions & 1 deletion iceoryx2/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ pub(crate) mod internal {
}
};

let mut number_of_dead_node_notifications = 0;
let cleanup_port_resources = |port_id| {
match port_id {
UniquePortId::Publisher(ref id) => {
Expand All @@ -399,7 +400,9 @@ pub(crate) mod internal {
return PortCleanupAction::SkipPort;
}
}
UniquePortId::Notifier(_) => (),
UniquePortId::Notifier(_) => {
number_of_dead_node_notifications += 1;
}
UniquePortId::Listener(ref id) => {
if let Err(e) = unsafe { remove_connection_of_listener::<S>(id, config) } {
debug!(from origin, "Failed to remove the listeners ({:?}) connection ({:?}).", id, e);
Expand Down Expand Up @@ -440,6 +443,10 @@ pub(crate) mod internal {
e);
}
}
} else {
if number_of_dead_node_notifications != 0 {
// println!("MUST SEND NOTIFICATION");
}
}

Ok(())
Expand Down
39 changes: 39 additions & 0 deletions iceoryx2/tests/node_death_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,45 @@ mod node_death_tests {
}
}

#[test]
fn notifier_of_dead_node_emits_death_event_when_configured<S: Test>() {
set_log_level(LogLevel::Error);
let _watchdog = Watchdog::new();
let mut config = generate_isolated_config();
let service_name = generate_service_name();
let notifier_dead_event = EventId::new(8);
config.global.node.cleanup_dead_nodes_on_creation = false;

let mut dead_node = S::create_test_node(&config).node;
let node = NodeBuilder::new()
.config(&config)
.create::<S::Service>()
.unwrap();

let dead_service = dead_node
.service_builder(&service_name)
.event()
.notifier_dead_event(Some(notifier_dead_event))
.create()
.unwrap();
let dead_notifier = dead_service.notifier_builder().create().unwrap();

let service = node.service_builder(&service_name).event().open().unwrap();
let listener = service.listener_builder().create().unwrap();

S::staged_death(&mut dead_node);
core::mem::forget(dead_notifier);

assert_that!(Node::<S::Service>::cleanup_dead_nodes(&config), eq CleanupState { cleanups: 1, failed_cleanups: 0});

let mut received_events = 0;
for event in listener.try_wait_one().unwrap().iter() {
assert_that!(*event, eq notifier_dead_event);
received_events += 1;
}
assert_that!(received_events, eq 1);
}

#[test]
fn event_service_is_removed_when_last_node_dies<S: Test>() {
let service_name = generate_service_name();
Expand Down

0 comments on commit 038d485

Please sign in to comment.