From 9790a7c2e8ed4dee9c65cabb10cabf53055450ee Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Wed, 13 Dec 2023 22:56:31 +0000 Subject: [PATCH] test: allow shutdown_token when #[cfg(test)] --- pageserver/src/task_mgr.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pageserver/src/task_mgr.rs b/pageserver/src/task_mgr.rs index 8747d9ad50..37e771560d 100644 --- a/pageserver/src/task_mgr.rs +++ b/pageserver/src/task_mgr.rs @@ -558,9 +558,14 @@ pub async fn shutdown_watcher() { /// cancelled. It can however be moved to other tasks, such as `tokio::task::spawn_blocking` or /// `tokio::task::JoinSet::spawn`. pub fn shutdown_token() -> CancellationToken { - SHUTDOWN_TOKEN - .try_with(|t| t.clone()) - .expect("shutdown_token() called in an unexpected task or thread") + let res = SHUTDOWN_TOKEN.try_with(|t| t.clone()); + + if cfg!(test) { + res.unwrap_or_default() + } else { + // tests need to call the same paths which need to use get the shutdown token + res.expect("shutdown_token() called in an unexpected task or thread") + } } /// Has the current task been requested to shut down?