PoiBlackTea opened a new pull request, #1118:
URL: https://github.com/apache/yunikorn-core/pull/1118
### Description
Fix flaky unit test `TestQuotaChangeTryPreemptionWithDifferentResTypes` in
`quota_preemptor_test.go`.
**Root Cause:**
In `createVictim`, creation times were calculated relative to
`time.Now()` with minute offsets (`-3m`, `-2m`, `-1m`). When unit tests execute
within the first 3 minutes of an hour (e.g. 19:01 UTC), `ask4` (-3m) falls into
the previous hour, while `ask42` (-1m) falls into the current hour. Since
preemption sorting truncates creation times to `time.Hour` and prioritizes
younger allocations, `ask42` (current hour) was incorrectly sorted before
`ask4` (previous hour), causing intermittent assertion failures (`ask42 !=
ask4`).
**Fix & Refactoring:**
1. Anchored `baseTime` in `createVictim` to the middle of the hour
(`time.Now().Truncate(time.Hour).Add(30 * time.Minute)`) so minute offsets
never cross hour boundaries.
2. Refactored `suitableVictims` into independent allocation slices for
each subtest to avoid object/state reuse across test cases, updating `node`
capacity to 200 accordingly.
### Type of change
Please delete options that are not relevant.
- [X] Bug Fix
- [ ] Improvement
- [ ] Feature
- [ ] Refactoring
- [ ] Documentation
### Jira issue
Jira ID : https://issues.apache.org/jira/browse/YUNIKORN-3334
- [ ] I have created a Jira issue for this pull request.
- [X] The Jira ID is part of the title of this pull request.
### AI Tooling
If an AI tool was used:
- [X] The PR includes the phrase "Generated by Antigravity IDE", where
Antigravity IDE is the name of the AI tool used.
- [X] My use of AI contributions follows the ASF legal policy.
Check https://www.apache.org/legal/generative-tooling.html for details.
### How has this been tested?
- [ ] New unit tests were added to cover new or changed code paths.
- [X] `make test_all` was run, and no failures reported.
- [ ] A pull request will be opened for new e2e tests
(apache/yunikorn-k8shim repository).
### Questions:
- [ ] The change needs documentation, a pull request for
apache/yunikorn-site repository will be created.
- [ ] There is breaking changes for older versions: jira is tagged with
`release-notes` label.
- [ ] The licenses files needs to be updated.
### Screenshots or other details
Duplicate JIRA Note: This flaky test was reported twice under
[YUNIKORN-3334](https://issues.apache.org/jira/browse/YUNIKORN-3334) and
[YUNIKORN-3342](https://issues.apache.org/jira/browse/YUNIKORN-3342). Using
[YUNIKORN-3334](https://issues.apache.org/jira/browse/YUNIKORN-3334) as it is
the earlier ticket.
Refactoring Note: The `suitableVictims` refactoring (separate allocation
instances per subtest) is not strictly required to fix the hour-boundary bug,
but was included to improve test isolation and prevent future state pollution.
Please let me know if you prefer to keep this PR focused solely on the time
boundary fix, and I can revert the refactoring commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]