Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion rosrust/src/api/ros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl Ros {
match period_logs.get_mut(&key) {
Some(next_log_time) => {
if now >= *next_log_time {
*next_log_time = get_next_log_time(*next_log_time, period);
*next_log_time = get_next_log_time(now, period);
self.log(level, msg, file, line);
}
}
Expand Down
27 changes: 18 additions & 9 deletions rosrust/tests/can_throttle_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,33 @@ fn can_throttle_logs() {
})
.unwrap();

// Wait for the pub/sub connection to be established
rosrust::sleep(rosrust::Duration::from_seconds(1));

let mut received_messages_counter = 0;

let rate = rosrust::rate(1.0);
for _ in 0..10 {
for item in rx.try_iter() {
println!("Received message at level {}: {}", item.0, item.1);
received_messages_counter += 1;
let rate = rosrust::rate(10.0);
let start_time = rosrust::now();
for i in 0..11 {
// Add a gap between t = 0.3s and t = 0.7s
// Logs should be produced at:
// t=0s, t=0.2s, t=0.7s, t=0.9s
if i < 4 || i > 6 {
rosrust::ros_info_throttle!(0.2, "[{}] info message", rosrust::now() - start_time);
}

rosrust::ros_info_throttle!(5.0, "info message");
rate.sleep();
}

for item in rx.try_iter() {
println!("Received message at level {}: {}", item.0, item.1);
received_messages_counter += 1;
}

if received_messages_counter == 0 {
panic!("Failed to receive data on /rosout_agg");
} else if received_messages_counter > 2 {
} else if received_messages_counter != 4 {
panic!(
"Received {} messages, not throttled",
"Received {} messages, not throttled properly",
received_messages_counter
);
}
Expand Down