Skip to content

Commit

Permalink
Check that consumers have their sample frequency set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Sparks committed Aug 15, 2024
1 parent 2bbe10b commit d502f50
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions async-nats/tests/jetstream_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,59 @@ mod jetstream {
}
}

#[tokio::test]
async fn consumer_configs_sample_frequency() {
let server = nats_server::run_server("tests/configs/jetstream.conf");

let client = ConnectOptions::new()
.event_callback(|err| async move { println!("error: {err:?}") })
.connect(server.client_url())
.await
.unwrap();

let js = async_nats::jetstream::new(client.clone());

let stream = js
.create_stream(stream::Config {
name: "StreamWithSampledConsumers".into(),
..Default::default()
})
.await
.unwrap();

{
let consumer = stream
.create_consumer(consumer::pull::Config {
name: Some("SampledPullConsumer".into()),
description: Some(
"See below to check that Ack Sampling has been set to 100%!".to_string(),
),
sample_frequency: 100, // <--- sample all the messages
..Default::default()
})
.await
.unwrap();

assert_eq!(100, consumer.cached_info().config.sample_frequency);
}

{
let consumer = stream
.create_consumer(consumer::pull::Config {
name: Some("SampledPushConsumer".into()),
description: Some(
"See below to check that Ack Sampling has been set to 100%!".to_string(),
),
sample_frequency: 100, // <--- sample all the messages
..Default::default()
})
.await
.unwrap();

assert_eq!(100, consumer.cached_info().config.sample_frequency);
}
}

#[tokio::test]
async fn timeout_out_request() {
let server = nats_server::run_server("tests/configs/jetstream.conf");
Expand Down

0 comments on commit d502f50

Please sign in to comment.