mirror of
https://github.com/neondatabase/neon.git
synced 2026-04-25 10:20:38 +00:00
fix macros more
This commit is contained in:
@@ -24,7 +24,7 @@ use crate::http::extract::Json;
|
||||
pub(in crate::http) async fn configure_failpoints(
|
||||
failpoints: Json<ConfigureFailpointsRequest>,
|
||||
) -> Response {
|
||||
if !fail::has_failpoints() {
|
||||
if !neon_failpoint::has_failpoints() {
|
||||
return JsonResponse::error(
|
||||
StatusCode::PRECONDITION_FAILED,
|
||||
"Cannot manage failpoints because neon was compiled without failpoints support",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use anyhow::{Context, Result};
|
||||
use fail::fail_point;
|
||||
use neon_failpoint::fail_point;
|
||||
use tokio_postgres::{Client, Transaction};
|
||||
use tracing::{error, info};
|
||||
|
||||
@@ -40,13 +40,13 @@ impl<'m> MigrationRunner<'m> {
|
||||
// middle of applying a series of migrations fails in an expected
|
||||
// manner
|
||||
if cfg!(feature = "testing") {
|
||||
let fail = (|| {
|
||||
fail_point!("compute-migration", |fail_migration_id| {
|
||||
let fail = async {
|
||||
fail_point!("compute-migration", |fail_migration_id: Option<String>| {
|
||||
migration_id == fail_migration_id.unwrap().parse::<i64>().unwrap()
|
||||
});
|
||||
|
||||
false
|
||||
})();
|
||||
}.await;
|
||||
|
||||
if fail {
|
||||
return Err(anyhow::anyhow!(format!(
|
||||
|
||||
@@ -45,7 +45,7 @@ pub enum FailpointAction {
|
||||
/// Sleep for a specified duration in milliseconds
|
||||
Sleep(u64),
|
||||
/// Return a value (for failpoints that support it)
|
||||
Return(String),
|
||||
Return(Option<String>),
|
||||
/// Exit the process immediately
|
||||
Exit,
|
||||
}
|
||||
@@ -59,7 +59,7 @@ pub enum FailpointResult {
|
||||
/// Continue normal execution
|
||||
Continue,
|
||||
/// Return early with a value
|
||||
Return(String),
|
||||
Return(Option<String>),
|
||||
/// Cancelled by cancellation token
|
||||
Cancelled,
|
||||
}
|
||||
@@ -264,7 +264,7 @@ pub async fn failpoint_with_cancellation(
|
||||
result
|
||||
}
|
||||
FailpointAction::Return(value) => {
|
||||
tracing::info!("Failpoint {} returning: {}", name, value);
|
||||
tracing::info!("Failpoint {} returning: {:?}", name, value);
|
||||
FailpointResult::Return(value)
|
||||
}
|
||||
FailpointAction::Exit => {
|
||||
@@ -280,12 +280,12 @@ fn parse_action(actions: &str) -> Result<FailpointAction> {
|
||||
"off" => Ok(FailpointAction::Off),
|
||||
"pause" => Ok(FailpointAction::Pause),
|
||||
"exit" => Ok(FailpointAction::Exit),
|
||||
"return" => Ok(FailpointAction::Return(String::new())),
|
||||
"return" => Ok(FailpointAction::Return(None)),
|
||||
_ => {
|
||||
// Try to parse return(value) format
|
||||
if let Some(captures) = regex::Regex::new(r"^return\(([^)]*)\)$")?.captures(actions) {
|
||||
let value = captures.get(1).unwrap().as_str().to_string();
|
||||
Ok(FailpointAction::Return(value))
|
||||
Ok(FailpointAction::Return(Some(value)))
|
||||
}
|
||||
// Try to parse sleep(millis) format
|
||||
else if let Some(captures) = regex::Regex::new(r"^sleep\((\d+)\)$")?.captures(actions) {
|
||||
|
||||
@@ -7,10 +7,11 @@ macro_rules! fail_point {
|
||||
if cfg!(feature = "testing") {
|
||||
match $crate::failpoint($name, None).await {
|
||||
$crate::FailpointResult::Continue => {},
|
||||
$crate::FailpointResult::Return(value) => {
|
||||
// For compatibility with fail crate, we need to handle the return value
|
||||
// This will be used in closures like |x| x pattern
|
||||
return Ok(value.parse().unwrap_or_default());
|
||||
$crate::FailpointResult::Return(None) => {
|
||||
return;
|
||||
},
|
||||
$crate::FailpointResult::Return(Some(value)) => {
|
||||
panic!("failpoint was configured with return(X) but Rust code does not pass a closure to map X to a return value");
|
||||
},
|
||||
$crate::FailpointResult::Cancelled => {},
|
||||
}
|
||||
@@ -22,7 +23,7 @@ macro_rules! fail_point {
|
||||
$crate::FailpointResult::Continue => {},
|
||||
$crate::FailpointResult::Return(value) => {
|
||||
let closure = $closure;
|
||||
return closure(value.as_str());
|
||||
return closure(value);
|
||||
},
|
||||
$crate::FailpointResult::Cancelled => {},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user