From 5540e3c627fe5888a41da1928c9528c0738618d8 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Thu, 12 Sep 2024 14:15:25 +0200 Subject: [PATCH 1/5] fix(buffer): Skip sleep if duration is zero --- relay-server/src/services/buffer/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/relay-server/src/services/buffer/mod.rs b/relay-server/src/services/buffer/mod.rs index 1b625e1b21..3936c4073c 100644 --- a/relay-server/src/services/buffer/mod.rs +++ b/relay-server/src/services/buffer/mod.rs @@ -142,7 +142,9 @@ impl EnvelopeBufferService { buffer: &mut PolymorphicEnvelopeBuffer, ) -> Result<(), SendError> { self.system_ready(buffer).await; - tokio::time::sleep(self.sleep).await; + if self.sleep > Duration::ZERO { + tokio::time::sleep(self.sleep).await; + } if let Some(project_cache_ready) = self.project_cache_ready.as_mut() { project_cache_ready.await?; self.project_cache_ready = None; From 4cf2613975cd0fb4f46e22a2c2bb2b232c84bdf7 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Thu, 12 Sep 2024 15:48:20 +0200 Subject: [PATCH 2/5] Fix test --- relay-server/src/services/buffer/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/relay-server/src/services/buffer/mod.rs b/relay-server/src/services/buffer/mod.rs index 3936c4073c..cd93320137 100644 --- a/relay-server/src/services/buffer/mod.rs +++ b/relay-server/src/services/buffer/mod.rs @@ -306,7 +306,6 @@ impl Service for EnvelopeBufferService { relay_log::trace!("EnvelopeBufferService received global config"); self.sleep = Duration::ZERO; // Try to pop } - else => break, } @@ -320,9 +319,9 @@ impl Service for EnvelopeBufferService { #[cfg(test)] mod tests { - use std::time::Duration; - + use hashbrown::HashSet; use relay_dynamic_config::GlobalConfig; + use std::time::Duration; use tokio::sync::mpsc; use uuid::Uuid; @@ -468,9 +467,10 @@ mod tests { tokio::time::sleep(Duration::from_millis(1000)).await; - // Project cache received only one envelope: - assert_eq!(project_cache_rx.len(), 1); // without throttling, this would be 5. - assert!(project_cache_rx.try_recv().is_ok()); - assert_eq!(project_cache_rx.len(), 0); + let mut messages = HashSet::new(); + while let Ok(value) = project_cache_rx.try_recv() { + messages.insert(value.variant()); + } + assert!(messages.contains("HandleDequeuedEnvelope")); } } From 9b2f653bfd793dce6dbea48ebc81d4eebb6c2b23 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Thu, 12 Sep 2024 15:48:55 +0200 Subject: [PATCH 3/5] Fix test --- relay-server/src/services/buffer/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/relay-server/src/services/buffer/mod.rs b/relay-server/src/services/buffer/mod.rs index cd93320137..af13f46418 100644 --- a/relay-server/src/services/buffer/mod.rs +++ b/relay-server/src/services/buffer/mod.rs @@ -319,9 +319,10 @@ impl Service for EnvelopeBufferService { #[cfg(test)] mod tests { + use std::time::Duration; + use hashbrown::HashSet; use relay_dynamic_config::GlobalConfig; - use std::time::Duration; use tokio::sync::mpsc; use uuid::Uuid; From 2fc16b4209ba88a2e80419f005b573a510bf3dbe Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Thu, 12 Sep 2024 15:53:17 +0200 Subject: [PATCH 4/5] Fix test --- relay-server/src/services/buffer/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/relay-server/src/services/buffer/mod.rs b/relay-server/src/services/buffer/mod.rs index af13f46418..ac864cd310 100644 --- a/relay-server/src/services/buffer/mod.rs +++ b/relay-server/src/services/buffer/mod.rs @@ -472,6 +472,12 @@ mod tests { while let Ok(value) = project_cache_rx.try_recv() { messages.insert(value.variant()); } - assert!(messages.contains("HandleDequeuedEnvelope")); + assert_eq!( + messages + .iter() + .filter(|&&x| x == "HandleDequeuedEnvelope") + .count(), + 1 + ); } } From 3769eb2b4208eb655640a5ba1193b718d0085bcb Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Thu, 12 Sep 2024 20:28:46 +0200 Subject: [PATCH 5/5] simplify test --- relay-server/src/services/buffer/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/relay-server/src/services/buffer/mod.rs b/relay-server/src/services/buffer/mod.rs index ac864cd310..83fea401c8 100644 --- a/relay-server/src/services/buffer/mod.rs +++ b/relay-server/src/services/buffer/mod.rs @@ -321,7 +321,6 @@ impl Service for EnvelopeBufferService { mod tests { use std::time::Duration; - use hashbrown::HashSet; use relay_dynamic_config::GlobalConfig; use tokio::sync::mpsc; use uuid::Uuid; @@ -466,16 +465,15 @@ mod tests { } addr.send(EnvelopeBuffer::Ready(project_key)); - tokio::time::sleep(Duration::from_millis(1000)).await; + tokio::time::sleep(Duration::from_millis(100)).await; + + let mut messages = vec![]; + project_cache_rx.recv_many(&mut messages, 100).await; - let mut messages = HashSet::new(); - while let Ok(value) = project_cache_rx.try_recv() { - messages.insert(value.variant()); - } assert_eq!( messages .iter() - .filter(|&&x| x == "HandleDequeuedEnvelope") + .filter(|message| matches!(message, ProjectCache::HandleDequeuedEnvelope(..))) .count(), 1 );