mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-17 02:12:56 +00:00
utils::failpoint_sleep_millis_async: ability to run an async block before sleeping
This commit is contained in:
@@ -57,16 +57,20 @@ pub mod serde_regex;
|
||||
/// use with fail::cfg("$name", "return(2000)")
|
||||
#[macro_export]
|
||||
macro_rules! failpoint_sleep_millis_async {
|
||||
($name:literal) => {{
|
||||
($name:literal) => {
|
||||
$crate::failpoint_sleep_millis_async!($name, async {})
|
||||
};
|
||||
($name:literal, $pre_sleep:expr) => {{
|
||||
let should_sleep: Option<std::time::Duration> = (|| {
|
||||
fail::fail_point!($name, |v: Option<_>| {
|
||||
let millis = v.unwrap().parse::<u64>().unwrap();
|
||||
Some(Duration::from_millis(millis))
|
||||
Some(::std::time::Duration::from_millis(millis))
|
||||
});
|
||||
None
|
||||
})();
|
||||
if let Some(d) = should_sleep {
|
||||
tracing::info!("failpoint {:?}: sleeping for {:?}", $name, d);
|
||||
$pre_sleep.await;
|
||||
tokio::time::sleep(d).await;
|
||||
tracing::info!("failpoint {:?}: sleep done", $name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user