diff --git a/relay-server/src/services/buffer/envelope_buffer/mod.rs b/relay-server/src/services/buffer/envelope_buffer/mod.rs index d7c2840e27..6205fcb42e 100644 --- a/relay-server/src/services/buffer/envelope_buffer/mod.rs +++ b/relay-server/src/services/buffer/envelope_buffer/mod.rs @@ -511,11 +511,10 @@ impl PartialEq for QueueItem { impl Eq for QueueItem {} -#[derive(Debug)] +#[derive(Debug, Clone)] struct Priority { readiness: Readiness, received_at: Instant, - // FIXME(jjbayer): `last_peek` is currently never updated, see https://github.com/getsentry/relay/pull/3960. last_peek: Instant, } @@ -529,22 +528,6 @@ impl Priority { } } -impl PartialEq for Priority { - fn eq(&self, other: &Self) -> bool { - self.readiness.ready() == other.readiness.ready() - && self.received_at == other.received_at - && self.last_peek == other.last_peek - } -} - -impl PartialOrd for Priority { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Eq for Priority {} - impl Ord for Priority { fn cmp(&self, other: &Self) -> Ordering { match (self.readiness.ready(), other.readiness.ready()) { @@ -565,7 +548,21 @@ impl Ord for Priority { } } -#[derive(Debug)] +impl PartialOrd for Priority { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl PartialEq for Priority { + fn eq(&self, other: &Self) -> bool { + self.cmp(other).is_eq() + } +} + +impl Eq for Priority {} + +#[derive(Debug, Clone, Copy)] struct Readiness { own_project_ready: bool, sampling_project_ready: bool, @@ -948,6 +945,24 @@ mod tests { assert_eq!(buffer.priority_queue.len(), 2); } + #[test] + fn test_total_order() { + let p1 = Priority { + readiness: Readiness { + own_project_ready: true, + sampling_project_ready: true, + }, + received_at: Instant::now(), + last_peek: Instant::now(), + }; + let mut p2 = p1.clone(); + p2.last_peek += Duration::from_millis(1); + + // Last peek does not matter because project is ready: + assert_eq!(p1.cmp(&p2), Ordering::Equal); + assert_eq!(p1, p2); + } + #[tokio::test] async fn test_last_peek_internal_order() { let mut buffer = EnvelopeBuffer::::new(mock_memory_checker());