Skip to content

Commit 22f0730

Browse files
authored
gh-122320: Limit dict key versions used by test_opcache. (gh-132961)
The `test_load_global_module()` test consumes a lot of dict key versions. Skip the test if we have consumed half of the available versions that can be used for the "load global" cache.
1 parent 336322b commit 22f0730

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Lib/test/test_opcache.py

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
_testinternalcapi = import_module("_testinternalcapi")
1717

1818

19+
def have_dict_key_versions():
20+
# max version value that can be stored in the load global cache. This is
21+
# determined by the type of module_keys_version and builtin_keys_version
22+
# in _PyLoadGlobalCache, uint16_t.
23+
max_version = 1<<16
24+
# use a wide safety margin (use only half of what's available)
25+
limit = max_version // 2
26+
return _testinternalcapi.get_next_dict_keys_version() < limit
27+
28+
1929
class TestBase(unittest.TestCase):
2030
def assert_specialized(self, f, opname):
2131
instructions = dis.get_instructions(f, adaptive=True)
@@ -1029,6 +1039,8 @@ def write(items):
10291039

10301040
@requires_specialization_ft
10311041
def test_load_global_module(self):
1042+
if not have_dict_key_versions():
1043+
raise unittest.SkipTest("Low on dict key versions")
10321044
def get_items():
10331045
items = []
10341046
for _ in range(self.ITEMS):

Modules/_testinternalcapi.c

+13
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,18 @@ gh_119213_getargs_impl(PyObject *module, PyObject *spam)
19851985
return Py_NewRef(spam);
19861986
}
19871987

1988+
/*[clinic input]
1989+
get_next_dict_keys_version
1990+
[clinic start generated code]*/
1991+
1992+
static PyObject *
1993+
get_next_dict_keys_version_impl(PyObject *module)
1994+
/*[clinic end generated code: output=e5405a509cf9d423 input=bd1cee7c6b9d3a3c]*/
1995+
{
1996+
PyInterpreterState *interp = _PyInterpreterState_GET();
1997+
uint32_t keys_version = interp->dict_state.next_keys_version;
1998+
return PyLong_FromLong(keys_version);
1999+
}
19882000

19892001
static PyObject *
19902002
get_static_builtin_types(PyObject *self, PyObject *Py_UNUSED(ignored))
@@ -2124,6 +2136,7 @@ static PyMethodDef module_functions[] = {
21242136
{"get_tracked_heap_size", get_tracked_heap_size, METH_NOARGS},
21252137
{"is_static_immortal", is_static_immortal, METH_O},
21262138
{"incref_decref_delayed", incref_decref_delayed, METH_O},
2139+
GET_NEXT_DICT_KEYS_VERSION_METHODDEF
21272140
{NULL, NULL} /* sentinel */
21282141
};
21292142

Modules/clinic/_testinternalcapi.c.h

+18-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)