-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async-nats: Support sample_freq
values containing a %
#1354
Conversation
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),
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for your contribution!
Closes #1353.
This PR updates
async-nats
's deserialization routine forsample_freq
in 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_freq
set to something ending in %.