-
-
Notifications
You must be signed in to change notification settings - Fork 3
Use Builder for InflightActivation
#523
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
base: main
Are you sure you want to change the base?
Conversation
|
Since the new builder boilerplate takes around 150 lines, these changes remove nearly 300 lines from the tests overall. We could cut even more code by...
|
markstory
left a comment
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.
Nice work. This should make writing tests simpler.
| .activation( | ||
| TaskActivationBuilder::default() | ||
| .id("0") | ||
| .taskname("pending_task") | ||
| .namespace(&namespace) | ||
| .received_at(received_at) | ||
| .build(), | ||
| ) |
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.
It would be nice if we could infer the activation properties from that are shared with the InflightActivation when using these builders. That could eliminate more boilerplate from tests and prevent mistakes where property values can diverge.
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.
Good point, I'll try this out!
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.
Done, it's even better now. In most tests, you can entirely avoid setting any values for the inner TaskActivation. And I actually found some mistakes where property values diverge. For example, expires was set on the TaskActivation but not the InflightActivation in several tests.
| } | ||
|
|
||
| #[test] | ||
| fn test_inflightactivation_builder() {} |
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.
Should this be implemented?
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 was thinking about writing some tests to make sure my builders are good, but I changed my mind because there are way too many combinations to check. I figure if the unit tests still pass, my builders work fine.
Description
Right now, every
InflightActivationin the unit tests is constructed manually field by field. This is extremely verbose and largely unnecessary, as most fields are set to use default values (for example, 0 when the type is an integer orNonewhen the type is anOption).We can reduce this boilerplate by using the builder pattern to construct these structs instead. That way, you only need to set the fields you are interested in, and it's easier to tell what's different between two
InflightActivations as you don't need to parse a million irrelevant fields that are all the same.For a demonstration, consider the two activations A and B below. What's the difference between them?
Activation A
Activation B
Activation A has an offset of 0 while B has an offset of 10. Even if it didn't take very long to figure that out, you still had to read quite a few irrelevant fields that are the same between both activations.
Now consider the same two activations constructed using a builder. We don't need to read all the fields because only the
offsetsetter is used! This tells us almost immediately that the offset is the only value that differs between the two tasks.Activation A
Activation B
As a result, it should be easier to write, read, and understand tests.
Details
derive_buildercrate to generate a builder forInflightActivationwith reasonable defaultsTaskActivationsince it's generated bysentry-protosInflightActivation { ... }in the tests with the builder