mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-10 07:48:19 -05:00
feat: make graceful shutdown clone
This commit is contained in:
@@ -712,6 +712,30 @@ mod tests {
|
||||
handle.block_on(shutdown);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_manager_graceful_shutdown_clone() {
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let manager = TaskManager::new(handle);
|
||||
let executor = manager.executor();
|
||||
|
||||
let val = Arc::new(AtomicBool::new(false));
|
||||
let c = val.clone();
|
||||
executor.spawn_critical_with_graceful_shutdown_signal(
|
||||
"grace clone",
|
||||
|shutdown| async move {
|
||||
let guard2 = shutdown.clone();
|
||||
let _guard = shutdown.await;
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
drop(guard2);
|
||||
c.store(true, Ordering::Relaxed);
|
||||
},
|
||||
);
|
||||
|
||||
manager.graceful_shutdown();
|
||||
assert!(val.load(Ordering::Relaxed));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_manager_graceful_shutdown() {
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
|
||||
@@ -69,6 +69,12 @@ impl Drop for GracefulShutdownGuard {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for GracefulShutdownGuard {
|
||||
fn clone(&self) -> Self {
|
||||
Self::new(Arc::clone(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// A Future that resolves when the shutdown event has been fired.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Shutdown(Shared<oneshot::Receiver<()>>);
|
||||
|
||||
Reference in New Issue
Block a user