-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add CLI flags -n, -t, T and -p #15
Conversation
I think in this case it's a bit more trivial as all of the stuff I upgraded are minor versions of popular crates which you can confidently assume have no breaking changes or anything but more importantly because this project is a standalone binary. If it was a library (especially one in an embedded context like the wifi drivers you are developing for instance) I would've definitely not made these so lightly but in this case, I do believe they are somewhat trivial. That said, I should've definitely mentioned my reasoning as to why I made them in the desc PR's description, thanks for pointing that out! |
Yeah you're welcome, agreed that it's pretty trivial in this case which is why I am not asking that you remove them from this PR and out into a separate one. Thanks for understanding. More review on the content of your PR soon... |
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.
@AntoniosBarotsis This looks great! Thank you for adding this. Just left a few questions/ideas.
@calebbourg Just pushed the changes, let me know if everything is resolved properly :) |
Love it! |
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.
Looking great, made a few recommendations inline. Open to discussing any of them.
src/requests.rs
Outdated
|
||
#[derive(Clone, Copy)] | ||
pub struct PostSchedulerBuilder { | ||
request_amount: Option<u32>, |
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.
@AntoniosBarotsis I think we should also change nearly ever mention of a request
to be post
or something contextually relevant. Does it even make sense to have a requests.rs
now? Consider changing it to sensor_posts.rs
as on idea.
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.
I've left a few mentions of request
where I feel like it makes sense, such as here. Let me know what you think.
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.
@jhodapp, probably missed my comment here :)
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.
Definitely a step in the right direction, made a suggestion to further rename things.
I added this section here which will make sure to log the response message as an error if the response code is not in the 200-299 range, makes it easier to immediately identify if something did not work. |
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.
Looks like the tests don't currently pass, I'm seeing 2 failures. Are you seeing these as well?
running 4 tests
test sensor_posts::tests::test_invalid_num_threads_low ... FAILED
test sensor_posts::tests::test_invalid_num_threads_high ... FAILED
test data::tests::air_purity_from_value_returns_correct_enum ... ok
test tests::verify_cli ... ok
failures:
---- sensor_posts::tests::test_invalid_num_threads_low stdout ----
thread 'sensor_posts::tests::test_invalid_num_threads_low' panicked at 'assertion failed: req_scheduler.is_err()', src/sensor_posts.rs:224:9
---- sensor_posts::tests::test_invalid_num_threads_high stdout ----
thread 'sensor_posts::tests::test_invalid_num_threads_high' panicked at 'assertion failed: req_scheduler.is_err()', src/sensor_posts.rs:233:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
sensor_posts::tests::test_invalid_num_threads_high
sensor_posts::tests::test_invalid_num_threads_low
test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Ah, should've run those again (probably a good enough excuse to set up a basic CI for this). Caleb suggested I move some of the validation (for what is considered a valid number of threads) out of the code and use Clap's validators instead. The tests don't fail anymore because the check would normally happen higher up the stack (as in, if you indeed try to run it with 0 or 11 threads which is what the tests are doing, it will fail with an error as it should). I'll fix the tests later today and make sure they run in GitHub actions from now on. |
Sounds great, I look forward to seeing your updates! |
Ok so, fixed the tests, they look like this now: let cli = Cli::try_parse_from(vec!["", "-p", "0"]);
assert!(cli.is_err());
let cli_err = cli.unwrap_err();
assert_eq!(cli_err.kind(), ErrorKind::ValueValidation); I just ensure that clap is failing to parse the input as we consider this amount of threads invalid. I also added the basic workflow I mentioned earlier although I believe it won't run until it's merged which is a bit annoying. Sorry for the many back and forths, last request review is this (waiting for reply) and everything should be fine after that! |
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.
Looks great Tony, thanks again for this! Tests pass for me now.
This closes #13.
Only added @jhodapp as a reviewer because that's who I was in contact with when working on this, feel free to add anyone else!
The relevant slack thread can be found here.
Added
Testing
From some manual testing, everything seems fine from what I can tell. It would be great if you could play around with it for a little bit to verify both that it works and that it feels as you'd expect (things like flag usage, default behavior, etc).
You can run it with
cargo r -- -h
or you can install it locally withcargo install --path .
and thenambi_mock_client -h
.Other Changes
This PR also upgraded to the latest version of clap and a bunch of other dependencies, moved a bunch of stuff around and added a logger.