Skip to content

Commit

Permalink
Make Sniffer::drop output more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Dec 16, 2024
1 parent 006d19e commit e503478
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions roles/tests-integration/tests/common/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ impl Sniffer {
check_on_drop: bool,
intercept_messages: Option<Vec<InterceptMessage>>,
) -> Self {
// Don't print backtrace on panic
std::panic::set_hook(Box::new(|_| {
println!();
}));
Self {
identifier,
listening_address,
Expand Down Expand Up @@ -576,23 +580,36 @@ macro_rules! assert_jd_message {
impl Drop for Sniffer {
fn drop(&mut self) {
if self.check_on_drop {
// Don't print backtrace on panic
std::panic::set_hook(Box::new(|_| {
println!();
}));
if !self.messages_from_downstream.is_empty() {
println!(
"Sniffer {}: You didn't handle all downstream messages: {:?}",
self.identifier, self.messages_from_downstream
);
panic!();
}
if !self.messages_from_upstream.is_empty() {
println!(
"Sniffer{}: You didn't handle all upstream messages: {:?}",
self.identifier, self.messages_from_upstream
);
panic!();
match (
self.messages_from_downstream.is_empty(),
self.messages_from_upstream.is_empty(),
) {
(true, true) => {}
(true, false) => {
println!(
"Sniffer {}: You didn't handle all upstream messages: {:?}",
self.identifier, self.messages_from_upstream
);
panic!();
}
(false, true) => {
println!(
"Sniffer {}: You didn't handle all downstream messages: {:?}",
self.identifier, self.messages_from_downstream
);
panic!();
}
(false, false) => {
println!(
"Sniffer {}: You didn't handle all downstream messages: {:?}",
self.identifier, self.messages_from_downstream
);
println!(
"Sniffer {}: You didn't handle all upstream messages: {:?}",
self.identifier, self.messages_from_upstream
);
panic!();
}
}
}
}
Expand Down

0 comments on commit e503478

Please sign in to comment.