forked from coreos/rpm-ostree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
try_fail_point!
macro and use it in more places
When I was debugging https://issues.redhat.com/browse/OCPBUGS-2866 it would have been quite convenient to have a failpoint set up in the transaction init path, because I could have forcibly injected a sleep there. Add one there, and in a few other places I semi-randomly chose by skimming through the code. The cost of this is very low, but if we find other bugs in the future it will likely be useful. Further, we can and should start using failpoints to forcibly inject errors in our CI tests. Since movement on review of tikv/fail-rs#68 has been slow, we just copy the code into our repo for now.
- Loading branch information
Showing
9 changed files
with
69 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Wrappers and utilities on top of the `fail` crate. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use anyhow::Result; | ||
|
||
/// TODO: Use https://github.com/tikv/fail-rs/pull/68 once it merges | ||
#[macro_export] | ||
macro_rules! try_fail_point { | ||
($name:expr) => {{ | ||
if let Some(e) = fail::eval($name, |msg| { | ||
let msg = msg.unwrap_or_else(|| "synthetic failpoint".to_string()); | ||
anyhow::Error::msg(msg) | ||
}) { | ||
return Err(From::from(e)); | ||
} | ||
}}; | ||
($name:expr, $cond:expr) => {{ | ||
if $cond { | ||
$crate::try_fail_point!($name); | ||
} | ||
}}; | ||
} | ||
|
||
/// Expose the `fail::fail_point` macro to C++. | ||
pub fn failpoint(p: &str) -> Result<()> { | ||
ostree_ext::glib::g_debug!("rpm-ostree", "{}", p); | ||
fail::fail_point!(p, |r| { | ||
Err(match r { | ||
Some(ref msg) => anyhow::anyhow!("{}", msg), | ||
None => anyhow::anyhow!("failpoint {}", p), | ||
}) | ||
}); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters