Skip to content

Commit

Permalink
refactor(iota-metrics): Remove channel_with_total (#3809)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian authored Oct 31, 2024
1 parent 490775b commit dfa9b26
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
22 changes: 0 additions & 22 deletions crates/iota-metrics/src/metered_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,28 +378,6 @@ pub fn channel<T>(size: usize, gauge: &IntGauge) -> (Sender<T>, Receiver<T>) {
)
}

/// Deprecated: use `monitored_mpsc::channel` instead.
#[track_caller]
pub fn channel_with_total<T>(
size: usize,
gauge: &IntGauge,
total_gauge: &IntCounter,
) -> (Sender<T>, Receiver<T>) {
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]
Expand Down
20 changes: 2 additions & 18 deletions crates/iota-metrics/src/tests/metered_channel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand Down

0 comments on commit dfa9b26

Please sign in to comment.