-
Notifications
You must be signed in to change notification settings - Fork 239
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
[YUNIKORN-2824] Refactor preemption_test.go #985
Conversation
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 guess this PR is still in draft. I will convert it.
Leaving a few quick reviews.
nodes []*Node | ||
iterator func() NodeIterator |
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.
We can remove the iterator
because nodes
can be used to generate an iterator
.
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.
Yeah. And I restructure the test function again , and keep the node
iterator
in the body, not as parameters. I hope it will be better. Thank you!
rootMaxRes map[string]string | ||
parentMaxRes map[string]string | ||
parentGuarRes map[string]string | ||
childQ1MaxRes map[string]string | ||
childQ1GuarRes map[string]string | ||
childQ2MaxRes map[string]string | ||
childQ2GuarRes map[string]string |
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'm not in favor of using 7 paramters to represent the queue configuration, especially when there is only one difference in childQ2GuarRes
in TestTryPreemption_NodeWithCapacityLesserThanAsk
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.
Thank you so much. I agree that there are too many parameters here. I jus reduced to 2 parameters: rootMaxRes and childQ2GuarRes.
Here I find there are 4 test functions:
As a draft here, I made a But when I want to merge test |
So at this moment, I only create a new test named
I skip the |
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.
To be honest, I don't really see this as an improvement. It makes the tests themselves hard to follow.
Thank you so much for your feedback! I completely understand your concerns regarding the readability of the combined tests. I think this boils down to finding the right balance between readability and avoiding code duplication. In the original code, the logic is certainly clearer with separated test cases, but there is a lot of duplicate code due to the similar steps involved in the preemption process. I believe this is why @manirajv06 raised the issue in the first place—hoping to simplify the tests and remove redundancy, while still preserving clarity. Please correct me if my understanding is off! As I reviewed the three test cases, I noticed that while their goals differ, the preemption process itself is quite similar across all of them, which is where the duplicated code comes from. Here's a breakdown of the common steps:
While I tried to reduce the duplicated code, I realize there’s still a challenge in balancing this with maintaining readability and clarity. The goal was to make the code more concise without sacrificing logic transparency. I've updated the code with a new approach that attempts to address these trade-offs. I'm not sure if it fully aligns with your expectations, but I'd really appreciate your thoughts on it. If you have any specific suggestions or ideas, I'd be more than happy to incorporate them. I’m open to any feedback to further improve it! |
I also had another thought. Since the logic is the key focus in these tests, and the only common parts across the three test cases are setting up app1 with its allocations and setting up app2, we could extract just those common steps into a helper function. By creating a function that handles setting up app1 and app2, we can reuse it across the three test cases. This way, the tests remain separated, keeping the logic for each scenario clear and focused, while still reducing some of the duplicate code. |
I think keeping the tests separate and extracting common logic into helper functions makes the most sense. It allows the tests to test one thing (I'm not generally a fan of combining everything into the case-based flows), but avoids repetition. |
Hi Craig. Thank you so much to review and comment, it is a great help for me to understand the next step. I love the idea of a helper function with separate tests. I will update the code, soon. |
I try to do the work step by step as below :
If anyone has any great suggestion, just let me know. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #985 +/- ##
==========================================
- Coverage 81.50% 81.29% -0.21%
==========================================
Files 97 97
Lines 12625 15463 +2838
==========================================
+ Hits 10290 12571 +2281
- Misses 2052 2611 +559
+ Partials 283 281 -2 ☔ View full report in Codecov by Sentry. |
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.
+1 LGTM.
Thank you so much for your suggestion and quick response. ❤️ |
What is this PR for?
Off late, lot of new tests has been added into preemption_test.go for several use cases. There is a room of improvement to simplify the whole tests especially by avoiding duplicates.
This PR focus on
TestTryPreemptionOnNode
,TestTryPreemption_NodeWithCapacityLesserThanAsk
, andTestTryPreemptionOnQueue
, those 3 tests can be merged together into single oneTestTryPreemptionCombined
and handle each cases through t.Run({}) construct.What type of PR is it?
Todos
What is the Jira issue?
https://issues.apache.org/jira/browse/YUNIKORN-2824
How should this be tested?
It should pass all unit tests.
Screenshots (if appropriate)
Questions: