async-nats: Support sample_freq values containing a %#1354
async-nats: Support sample_freq values containing a %#1354Jarema merged 5 commits intonats-io:mainfrom
sample_freq values containing a %#1354Conversation
|
Hey! Thanks for addressing the issue. The The best way to test it send a custom I wrote a quick and dirty example how to sent such request. #[tokio::test]
async fn sample_frequency() {
let client = async_nats::ConnectOptions::new()
.connect("localhost:4222")
.await
.unwrap();
let jetstream = async_nats::jetstream::new(client);
jetstream
.get_or_create_stream(stream::Config {
name: "events".to_string(),
subjects: vec!["events.>".to_string()],
..Default::default()
})
.await
.unwrap();
let consumer = json!({
"stream_name": "events",
"config": {
"name": "consumer",
"sample_freq": "10%",
},
});
let info: Response<Info> = jetstream
.request("CONSUMER.CREATE.events", &consumer)
.await
.unwrap();
match info {
Response::Ok(info) => {
assert_eq!(info.config.sample_frequency, 10);
}
Response::Err { error } => panic!("expected ok response, got: {:?}", error),
}
} |
Jarema
left a comment
There was a problem hiding this comment.
please add the mentioned test.
|
@Jarema In fact, I'd like to extend that test with your suggestion, as that test's purpose is to check the de/ser of |
|
nice catch! yes, it make sense to fix it, however, let's make it a separate PR. |
This reverts commit 448b954.
|
Done in 5c5b36e. |
Jarema
left a comment
There was a problem hiding this comment.
LGTM!
Thanks for your contribution!
Closes #1353.
This PR updates
async-nats's deserialization routine forsample_freqin consumers to account for a terminating '%', which is seen in the wild when managing NATS resources using Terraform / OpenTofu.The changed code is partially tested by the same test added in #1300, but currently does not contain a test for the new case.
I instead tested it against the setup outlined in #1353.
I'd like to add such a case, but I'm not sure how to do so, as Rust's type system forbids me from creating a consumer with
sample_freqset to something ending in %.