Skip to content

Commit

Permalink
refactor(12089): update test to avoid the looping and global (to pack…
Browse files Browse the repository at this point in the history
…age tests) panic hook manipulation
  • Loading branch information
wiedld committed Aug 23, 2024
1 parent 720feb1 commit afd4560
Showing 1 changed file with 14 additions and 33 deletions.
47 changes: 14 additions & 33 deletions datafusion/common-runtime/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,48 +79,29 @@ impl<R: 'static> SpawnedTask<R> {
mod tests {
use super::*;

use std::{
future::{pending, Pending},
sync::{Arc, Mutex},
};
use std::future::{pending, Pending};

use tokio::runtime::Runtime;

#[tokio::test]
async fn runtime_shutdown() {
// capture the panic message
let panic_msg = Arc::new(Mutex::new(None));
let captured_panic_msg = Arc::clone(&panic_msg);
std::panic::set_hook(Box::new(move |e| {
let mut guard = captured_panic_msg.lock().unwrap();
*guard = Some(e.to_string());
}));

for _ in 0..30 {
let rt = Runtime::new().unwrap();
let join = rt.spawn(async {
let task = SpawnedTask::spawn(async {
let rt = Runtime::new().unwrap();
let task = rt
.spawn(async {
SpawnedTask::spawn(async {
let fut: Pending<()> = pending();
fut.await;
unreachable!("should never return");
});
let _ = task.join_unwind().await;
});

// caller shutdown their DF runtime (e.g. timeout, error in caller, etc)
rt.shutdown_background();
})
})
.await
.unwrap();

// race condition
// poll occurs during shutdown (buffered stream poll calls, etc)
let _ = join.await;
}
// caller shutdown their DF runtime (e.g. timeout, error in caller, etc)
rt.shutdown_background();

// demonstrate that we hit the unreachable code
let maybe_panic = panic_msg.lock().unwrap().clone();
assert_eq!(
maybe_panic, None,
"should not have rt thread panic, instead found {:?}",
maybe_panic
);
// race condition
// poll occurs during shutdown (buffered stream poll calls, etc)
let _ = task.join_unwind().await;
}
}

0 comments on commit afd4560

Please sign in to comment.