Content-Length: 271977 | pFad | http://github.com/python/cpython/issues/155146

ad test_detach_materialized_dict_no_memory depends on the exact number of allocations · Issue #155146 · python/cpython · GitHub
Skip to content

test_detach_materialized_dict_no_memory depends on the exact number of allocations #155146

Description

@serhiy-storchaka

Bug report

test_class.TestInlineValues.test_detach_materialized_dict_no_memory (added in gh-124547) uses _testcapi.set_nomemory(0, 1) to fail the first allocation after that call, and assumes that this is the allocation which detaches the instance dictionary from the object. But set_nomemory() hooks all three allocator domains, so any other allocation which happens first consumes the single failure.

The target is one allocation wide. Failing the n-th allocation instead on Linux: n=0 works as intended, n=1..4 kill the process with MemoryError, and for n>=5 no MemoryError occurs during deallocation at all.

The test subprocess imports only test.support and _testcapi, so any change of what test.support allocates at import time can shift the sequence.

#155120 is such a change: it adds three functions and a constant to Lib/test/support/__init__.py, none of which is used by this test. With it the test fails on the Windows / Build and test (x64, tail-call) job:

    assert False, "KeyError not raised"
AssertionError: KeyError not raised

MemoryError was reported as unraisable during deallocation, but the dictionary was not cleared, because the failing allocation was not the one in the detach code. This is deterministic — 3 failures out of 3, including a re-run of the same commit — while the same job passes on the last 6 commits on main and on the other recent pull requests I checked. It does not reproduce on Linux, nor on the other Windows configurations.

The tested invariant is correct, only the way it is tested is fragile. I propose to try to fail each of the first allocations and to accept the first one which fails in the detach code.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: http://github.com/python/cpython/issues/155146

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy