use tokio::task::JoinHandle;
pub(crate) async fn observe_driver_handle(handle: JoinHandle<()>) {
match handle.await {
Ok(()) => {}
Err(err) if err.is_panic() => {
#[cfg(feature = "tracing")]
tracing::error!(
error = %err,
"tsoracle client driver task panicked; subsequent requests will fail with ClientError::DriverGone"
);
#[cfg(not(feature = "tracing"))]
let _ = err;
}
Err(err) => {
#[cfg(feature = "tracing")]
tracing::error!(
error = %err,
"tsoracle client driver task terminated abnormally (cancelled?)"
);
#[cfg(not(feature = "tracing"))]
let _ = err;
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn enable_tracing() {
use tracing_subscriber::filter::LevelFilter;
let _ = tracing_subscriber::fmt()
.with_max_level(LevelFilter::TRACE)
.with_test_writer()
.try_init();
}
#[tokio::test]
async fn observe_returns_on_clean_completion() {
let handle = tokio::spawn(async {});
observe_driver_handle(handle).await;
}
#[tokio::test]
async fn observe_absorbs_panic_without_repanicking() {
enable_tracing();
let handle = tokio::spawn(async {
panic!("synthetic driver-task panic");
});
observe_driver_handle(handle).await;
}
#[tokio::test]
async fn observe_handles_aborted_handle() {
enable_tracing();
let handle = tokio::spawn(async {
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
});
handle.abort();
observe_driver_handle(handle).await;
}
}