diff --git a/compute_tools/src/http/routes/failpoints.rs b/compute_tools/src/http/routes/failpoints.rs index 8f5da99963..6b1fc6d529 100644 --- a/compute_tools/src/http/routes/failpoints.rs +++ b/compute_tools/src/http/routes/failpoints.rs @@ -24,7 +24,7 @@ use crate::http::extract::Json; pub(in crate::http) async fn configure_failpoints( failpoints: Json, ) -> 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", diff --git a/compute_tools/src/migration.rs b/compute_tools/src/migration.rs index c5e05822c0..2acde44044 100644 --- a/compute_tools/src/migration.rs +++ b/compute_tools/src/migration.rs @@ -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| { migration_id == fail_migration_id.unwrap().parse::().unwrap() }); false - })(); + }.await; if fail { return Err(anyhow::anyhow!(format!( diff --git a/libs/neon_failpoint/src/lib.rs b/libs/neon_failpoint/src/lib.rs index 0f692a6bdf..95c412e7e7 100644 --- a/libs/neon_failpoint/src/lib.rs +++ b/libs/neon_failpoint/src/lib.rs @@ -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), /// 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), /// 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 { "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) { diff --git a/libs/neon_failpoint/src/macros.rs b/libs/neon_failpoint/src/macros.rs index 7029b4cf3e..4870f537b5 100644 --- a/libs/neon_failpoint/src/macros.rs +++ b/libs/neon_failpoint/src/macros.rs @@ -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 => {}, }