From af688d8344b3331fe21a5be9cfab86c9fcdd76e9 Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Mon, 1 Apr 2024 17:10:52 +0000 Subject: [PATCH 1/3] Deleting a nonexistent producer should succeed --- oximeter/collector/src/agent.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/oximeter/collector/src/agent.rs b/oximeter/collector/src/agent.rs index 33146b3579..98a4dbc009 100644 --- a/oximeter/collector/src/agent.rs +++ b/oximeter/collector/src/agent.rs @@ -679,8 +679,10 @@ impl OximeterAgent { >, id: Uuid, ) -> Result<(), Error> { - let (_info, task) = - tasks.remove(&id).ok_or_else(|| Error::NoSuchProducer(id))?; + let Some((_info, task)) = tasks.remove(&id) else { + // We have no such producer, so good news, we've removed it! + return Ok(()); + }; debug!( self.log, "removed collection task from set"; @@ -1121,4 +1123,26 @@ mod tests { assert_eq!(stats.failed_collections.len(), 1); logctx.cleanup_successful(); } + + #[tokio::test] + async fn test_delete_nonexistent_producer_succeeds() { + let logctx = + test_setup_log("test_delete_nonexistent_producer_succeeds"); + let log = &logctx.log; + + // Spawn an oximeter collector ... + let collector = OximeterAgent::new_standalone( + Uuid::new_v4(), + SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0), + crate::default_refresh_interval(), + None, + log, + ) + .await + .unwrap(); + assert!( + collector.delete_producer(Uuid::new_v4()).await.is_ok(), + "Deleting a non-existent producer should be OK" + ); + } } From f4736972c83bf65c0edf0ead74c7e21898196b7d Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Mon, 1 Apr 2024 17:18:12 +0000 Subject: [PATCH 2/3] Remove unused variant --- oximeter/collector/src/lib.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/oximeter/collector/src/lib.rs b/oximeter/collector/src/lib.rs index 596c0dc785..fa699d67d8 100644 --- a/oximeter/collector/src/lib.rs +++ b/oximeter/collector/src/lib.rs @@ -60,22 +60,13 @@ pub enum Error { #[error(transparent)] ResolveError(#[from] ResolveError), - #[error("No producer is registered with ID")] - NoSuchProducer(Uuid), - #[error("Error running standalone")] Standalone(#[from] anyhow::Error), } impl From for HttpError { fn from(e: Error) -> Self { - match e { - Error::NoSuchProducer(id) => HttpError::for_not_found( - None, - format!("No such producer: {id}"), - ), - _ => HttpError::for_internal_error(e.to_string()), - } + HttpError::for_internal_error(e.to_string()) } } From 412032e4dc705db190017d5e855954ebaca5e64d Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Mon, 1 Apr 2024 17:56:50 +0000 Subject: [PATCH 3/3] cleanup test artifacts on success --- oximeter/collector/src/agent.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/oximeter/collector/src/agent.rs b/oximeter/collector/src/agent.rs index 98a4dbc009..d3ed56a7a7 100644 --- a/oximeter/collector/src/agent.rs +++ b/oximeter/collector/src/agent.rs @@ -1144,5 +1144,6 @@ mod tests { collector.delete_producer(Uuid::new_v4()).await.is_ok(), "Deleting a non-existent producer should be OK" ); + logctx.cleanup_successful(); } }