From dfa9b26fcedc571ac533731a33cacda8a9023720 Mon Sep 17 00:00:00 2001 From: "Ching-Hua (Vivian) Lin" Date: Thu, 31 Oct 2024 15:55:07 +0800 Subject: [PATCH] refactor(iota-metrics): Remove channel_with_total (#3809) --- crates/iota-metrics/src/metered_channel.rs | 22 ------------------- .../src/tests/metered_channel_tests.rs | 20 ++--------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/crates/iota-metrics/src/metered_channel.rs b/crates/iota-metrics/src/metered_channel.rs index 39b875a8a62..210580e1b4b 100644 --- a/crates/iota-metrics/src/metered_channel.rs +++ b/crates/iota-metrics/src/metered_channel.rs @@ -378,28 +378,6 @@ pub fn channel(size: usize, gauge: &IntGauge) -> (Sender, Receiver) { ) } -/// Deprecated: use `monitored_mpsc::channel` instead. -#[track_caller] -pub fn channel_with_total( - size: usize, - gauge: &IntGauge, - total_gauge: &IntCounter, -) -> (Sender, Receiver) { - gauge.set(0); - let (sender, receiver) = mpsc::channel(size); - ( - Sender { - inner: sender, - gauge: gauge.clone(), - }, - Receiver { - inner: receiver, - gauge: gauge.clone(), - total: Some(total_gauge.clone()), - }, - ) -} - /// Defines an asynchronous method `with_permit` for working with a permit to /// send a message. #[async_trait] diff --git a/crates/iota-metrics/src/tests/metered_channel_tests.rs b/crates/iota-metrics/src/tests/metered_channel_tests.rs index 99b64706e65..b3e85fd1a01 100644 --- a/crates/iota-metrics/src/tests/metered_channel_tests.rs +++ b/crates/iota-metrics/src/tests/metered_channel_tests.rs @@ -7,10 +7,10 @@ use futures::{ FutureExt, task::{Context, Poll, noop_waker}, }; -use prometheus::{IntCounter, IntGauge}; +use prometheus::IntGauge; use tokio::sync::mpsc::error::TrySendError; -use super::{channel, channel_with_total}; +use super::channel; #[tokio::test] async fn test_send() { @@ -26,22 +26,6 @@ async fn test_send() { assert_eq!(counter.get(), 0); } -#[tokio::test] -async fn test_total() { - let counter = IntGauge::new("TEST_COUNTER", "test").unwrap(); - let counter_total = IntCounter::new("TEST_TOTAL", "test_total").unwrap(); - let (tx, mut rx) = channel_with_total(8, &counter, &counter_total); - - assert_eq!(counter.get(), 0); - let item = 42; - tx.send(item).await.unwrap(); - assert_eq!(counter.get(), 1); - let received_item = rx.recv().await.unwrap(); - assert_eq!(received_item, item); - assert_eq!(counter.get(), 0); - assert_eq!(counter_total.get(), 1); -} - #[tokio::test] async fn test_empty_closed_channel() { let counter = IntGauge::new("TEST_COUNTER", "test").unwrap();