Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log throttling #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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