Skip to content

test: pin fail-loud behavior when InternalPage.alloc() raises mid-alloc - #449

Merged
RixinLiu merged 2 commits into
ovg-project:mainfrom
rishabhsinha17:test/page-alloc-fail-loud
Aug 18, 2026
Merged

test: pin fail-loud behavior when InternalPage.alloc() raises mid-alloc#449
RixinLiu merged 2 commits into
ovg-project:mainfrom
rishabhsinha17:test/page-alloc-fail-loud

Conversation

@rishabhsinha17

@rishabhsinha17 rishabhsinha17 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #430: the review there narrowed the rollback handler to alloc_page() so that InternalPage.alloc()'s "Not enough free blocks" invariant failure stays fail-loud, and asked for a regression test where page.alloc() raises to pin the distinction (#430 (comment)). The handler was narrowed in 79794d9; the test was not added. This adds it.

Changes

Two tests in tests/test_alloc_rollback.py, one per page.alloc() call site: a page picked from avail_pages (the case where rollback cannot restore state, since _pick_avail_page() has already removed the page while its blocks are not yet in ret_index) and a freshly allocated page. Both assert the RuntimeError propagates out of alloc() instead of being downgraded to a None miss.

Validation

python -m pytest tests/test_alloc_rollback.py -> 8 passed. ruff, isort, and mypy --python-version 3.10 clean on the file. No manifest change needed: the file is already classified cpu.

The rollback handler added in ovg-project#430 was narrowed to alloc_page() during
review so that InternalPage.alloc()'s "Not enough free blocks" invariant
failure stays fail-loud: by the time page.alloc() runs,
_pick_avail_page() may already have removed the page from avail_pages
while its blocks are not yet in ret_index, so rollback could not restore
it. The review asked for a regression test where page.alloc() raises to
pin that distinction; this adds one for both call sites (a page picked
from avail_pages and a freshly allocated page), asserting the error
propagates instead of being downgraded to an allocation miss.
@rishabhsinha17
rishabhsinha17 force-pushed the test/page-alloc-fail-loud branch from 4ab3ad2 to eb3e7e0 Compare August 15, 2026 18:41
Comment thread tests/test_alloc_rollback.py Outdated
# invariant failure must propagate, not degrade into a None miss (#430).
manager = make_manager(fail_after=1)
assert manager.alloc(2) == [0, 1]
manager.avail_pages[0].__class__ = ExplodingPage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use monkeypatch to make page.alloc() raise instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5e25a3a: both tests now inject the raise with monkeypatch (instance attribute for the avail_pages case, class attribute for the page that does not exist until alloc() creates it) and the ExplodingPage subclass is gone. 8 passed, ruff/isort/mypy clean.

@RixinLiu

Copy link
Copy Markdown
Collaborator

Thanks for the follow-up, good to have this

@RixinLiu
RixinLiu merged commit 7ac1cf2 into ovg-project:main Aug 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants