mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-19 06:00:38 +00:00
test: allow shutdown_token when #[cfg(test)]
This commit is contained in:
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user