Skip to content

test: Isolate the memory tracking tests from other buffers - #1892

Merged
polvalente merged 1 commit into
elixir-nx:mainfrom
georgeguimaraes:fix/memory-tracking-test-isolation
Oct 22, 2026
Merged

polvalente merged 1 commit into
elixir-nx:mainfrom
georgeguimaraes:fix/memory-tracking-test-isolation

Conversation

@georgeguimaraes

Copy link
Copy Markdown
Member

EXLA.MemoryTrackingTest was flaky on CI (e.g. left: 20, right: 400020). ExUnit starts the next test as soon as it gets :test_finished, before the previous test process actually exits, so buffers it still holds can get freed in the middle of the next test and mess up the stats. the 400,000 bytes are t2 from the donation test.

so the module now uses its own client (:memory_tracking_host), and every buffer a test creates gets freed in on_exit, which runs before the next test even if an assertion fails.

I could repro it locally by freeing a 400 KB :host buffer a few ms into each test: failed on every seed before, passes now.

The memory statistics count every buffer of a client. ExUnit starts the next test when it gets the result of a test, before the process of that test exits. So a buffer that a test keeps can be freed during the next test, and a check of the statistics fails. For example, the donation test kept 400,000 bytes of :host buffers until its process exited.

The tests now use a client that no other test uses. Each buffer that a test makes is freed in an on_exit callback, which ExUnit runs before the next test, also when an assertion fails.
@georgeguimaraes
georgeguimaraes force-pushed the fix/memory-tracking-test-isolation branch from 1069721 to 4cc1432 Compare October 21, 2026 22:06
@polvalente
polvalente merged commit f9e429b into elixir-nx:main Oct 22, 2026
9 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.

2 participants