Skip to content

Commit

Permalink
Replace panic with return, and make sure process_events finishes prop…
Browse files Browse the repository at this point in the history
…erly
  • Loading branch information
alpeb committed Dec 28, 2023
1 parent f3c5459 commit 956a8c7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cni-repair-controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn process_events(
tracing::warn!(%namespace, %name, "Dropped event (channel full)");
metrics.queue_overflow.inc();
}
Err(TrySendError::Closed(_)) => panic!("Channel closed or dropped"),
Err(TrySendError::Closed(_)) => return,
}
}
}
Expand Down Expand Up @@ -235,12 +235,13 @@ mod test {
watcher::Event::Applied(pod3),
]);

tokio::spawn(process_events(stream, tx, metrics));
let process_events_handle = tokio::spawn(process_events(stream, tx, metrics));
time::sleep(Duration::from_secs(2)).await;
let msg = rx.try_recv();
let object_ref = msg.unwrap();
assert_eq!(object_ref.name, Some("pod2".to_string()));
let msg = rx.try_recv();
assert_eq!(msg, Err(TryRecvError::Disconnected));
assert!(process_events_handle.is_finished());
}
}

0 comments on commit 956a8c7

Please sign in to comment.