Skip to content

Commit 120fce0

Browse files
committed
Update test_json.test_recursion
On FreeBSD 16 with a default stack size of 512 MB, the json C implementation no longer raises RecursionError in test_highly_nested_objects_encoding(). Reduce max_depth from 5_000 to 2_000 so test_highly_nested_objects_encoding() of the Python implementation only takes 1.6 seconds, instead of 12 seconds.
1 parent c031a55 commit 120fce0

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

‎Lib/test/test_json/test_recursion.py‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,35 @@ def test_highly_nested_objects_decoding(self):
9191
@support.skip_emscripten_stack_overflow()
9292
@support.requires_resource('cpu')
9393
def test_highly_nested_objects_encoding(self):
94-
# See #12051
94+
# See issue gh-56260
95+
96+
# With max_depth=2_000 on Linux, the Python implementation takes around
97+
# 2 seconds to raise RecursionError, whereas the C implementation only
98+
# takes around 160 ms.
99+
max_depth = 2_000
95100
l, d = [], {}
96-
for x in range(500_000):
101+
for x in range(max_depth * 10):
97102
l, d = [l], {'k':d}
98-
with self.assertRaises(RecursionError):
99-
with support.infinite_recursion(5000):
103+
104+
# Don't use assertRaises(RecursionError): on FreeBSD 16 with a default
105+
# stack size of 512 MiB, the C implementation doesn't raise
106+
# RecursionError.
107+
try:
108+
with support.infinite_recursion(max_depth):
100109
self.dumps(l)
101-
with self.assertRaises(RecursionError):
102-
with support.infinite_recursion(5000):
110+
except RecursionError:
111+
pass
112+
try:
113+
with support.infinite_recursion(max_depth):
103114
self.dumps(d)
115+
except RecursionError:
116+
pass
104117

105118
@support.skip_if_huge_c_stack()
106119
@support.skip_emscripten_stack_overflow()
107120
@support.skip_wasi_stack_overflow()
108121
def test_endless_recursion(self):
109-
# See #12051
122+
# See issue gh-56260
110123
class EndlessJSONEncoder(self.json.JSONEncoder):
111124
def default(self, o):
112125
"""If check_circular is False, this will keep adding another list."""

0 commit comments

Comments
 (0)