Repository navigation
Fix off-by-one page count in PageUtil for divisible totals - #15446
Conversation
|
@vasiliy-mikhailov Please fix the ci problem. |
Signed-off-by: vmihaylov <vasiliy.mikhailov@gmail.com>
|
Thanks for the heads-up. The CI failure was a Spotless format issue (a blank line in the added test needed the project indent). Ran spotless:apply and pushed, the check is green locally now. |
…ivision fix Signed-off-by: Vasiliy Mikhailov <vasiliy.mikhailov@gmail.com>
|
Fixed. The remaining CI failure was a pre-existing test, CatalogServiceV2ImplTest.testListService, that hardcoded the old off-by-one page count (it asserted 4 pages for 3 services at pageSize 1, with the message describing the buggy (totalCount / pageSize) + 1 formula). The PageUtil fix corrects that to 3 (a divisible total has no extra page), so I updated the assertion and its message to match. Pushed. |
|
reopen for cla |
|
Thanks for your this PR. 🙏 感谢您提交的PR。 🙏 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
PageUtilcomputes the page count as(totalCount / pageSize) + 1, whichreports one page too many whenever
totalCountis an exact multiple ofpageSize(e.g. 9 items at 3 per page yields 4 instead of 3), and reports 1page for an empty result. Callers that iterate
1..pagesAvailablethen visit atrailing empty page.
Use ceiling division
(totalCount + pageSize - 1) / pageSize. One existingassertion in
PageUtilTestencoded the old off-by-one value (2 pages for 2items at 2 per page) and is corrected to 1; a test for the exactly-divisible
case is added.
Verifying this change
PageUtilTest(which includes the added cases) fails on the currentdevelopand passes with this change:Before the fix (on
develop):After the fix:
AI assistance disclosure
This contribution was produced with the help of an AI pipeline. The pipeline processed a large amount of source code to surface suspected bugs, reproduced a subset of them with failing unit tests and generated candidate fixes, and prepared pull requests from the ones that held up. Each PR was then reviewed and verified by a human before being opened: the fix and test were checked by hand and the test was confirmed to fail before the change and pass after.