-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fail: check condition only when its failpoint is open #48
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,14 +585,21 @@ pub fn list() -> Vec<(String, String)> { | |
} | ||
|
||
#[doc(hidden)] | ||
pub fn eval<R, F: FnOnce(Option<String>) -> R>(name: &str, f: F) -> Option<R> { | ||
pub fn eval<R, F: FnOnce(Option<String>) -> R>( | ||
name: &str, | ||
f: F, | ||
cond: impl FnOnce() -> bool, | ||
BusyJay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> Option<R> { | ||
let p = { | ||
let registry = REGISTRY.registry.read().unwrap(); | ||
match registry.get(name) { | ||
None => return None, | ||
Some(p) => p.clone(), | ||
} | ||
}; | ||
if !cond() { | ||
return None; | ||
} | ||
p.eval(name).map(f) | ||
} | ||
|
||
|
@@ -727,18 +734,22 @@ fn set( | |
#[cfg(feature = "failpoints")] | ||
macro_rules! fail_point { | ||
($name:expr) => {{ | ||
$crate::eval($name, |_| { | ||
panic!("Return is not supported for the fail point \"{}\"", $name); | ||
}); | ||
$crate::eval( | ||
$name, | ||
|_| { | ||
panic!("Return is not supported for the fail point \"{}\"", $name); | ||
}, | ||
|| true, | ||
); | ||
}}; | ||
($name:expr, $e:expr) => {{ | ||
if let Some(res) = $crate::eval($name, $e) { | ||
if let Some(res) = $crate::eval($name, $e, || true) { | ||
return res; | ||
} | ||
}}; | ||
($name:expr, $cond:expr, $e:expr) => {{ | ||
if $cond { | ||
fail_point!($name, $e); | ||
if let Some(res) = $crate::eval($name, $e, || $cond) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes it hard to share mutable states between $cond and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If true then we better add a test case that captures the expected behavior. @gengliqi can you try adding a test case that shares mutable references between the two expressions and seeing if they worked previously but don't work after this patch? |
||
return res; | ||
} | ||
}}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use impl trait here too.