Skip to content

Commit b0011aa

Browse files
tests/test_memory.py: avoid spurious failures on non-linux.
Non-Linux machines have unreliable RSS values on Github.
1 parent 67fba9e commit b0011aa

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tests/test_memory.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -199,24 +199,24 @@ def get_stat():
199199
gc.collect()
200200
get_stat()
201201

202-
# Check memory leak is as expected.
203-
for i in range(3, len(state.rsss)):
204-
drss = state.rsss[i] - state.rsss[i-1]
202+
if platform.system() == 'Linux':
203+
rss_delta = state.rsss[-1] - state.rsss[3]
204+
print(f'{rss_delta=}')
205205
pv = platform.python_version_tuple()
206206
pv = (int(pv[0]), int(pv[1]))
207207
if pv < (3, 11):
208208
# Python < 3.11 has less reliable memory usage so we exclude.
209-
print(f'test_4125(): Not checking on {platform.python_version_tuple()=} because < 3.11.')
210-
elif platform.system() == 'Darwin':
211-
print(f'test_4125(): Not checking on {platform.system()=} because RSS seems to be unreliable.')
209+
print(f'test_4125(): Not checking on {platform.python_version()=} because < 3.11.')
212210
elif pymupdf.mupdf_version_tuple < (1, 25, 2):
213-
drss_expected = 4915200
214-
e = abs(1 - drss / drss_expected)
215-
print(f'test_4125(): {i=} {e=}')
216-
assert e < 0.15, f'{i=}: {drss_expected} {drss} {e=}.'
211+
rss_delta_expected = 4915200 * (len(state.rsss) - 3)
212+
assert abs(1 - rss_delta / rss_delta_expected) < 0.15, f'{rss_delta_expected=}'
217213
else:
218-
# Bug fixed in MuPDF-1.26 and hopefully MuPDF-1.25.2. We still see
219-
# some fluctuations in RSS usage, perhaps worse for older Python
220-
# versions.
221-
e = 200*1000
222-
assert abs(drss) <= e, f'{i=}: {drss=} {e=}.'
214+
# Before the fix, each iteration would leak 4.9MB.
215+
rss_delta_max = 100*1000 * (len(state.rsss) - 3)
216+
assert rss_delta < rss_delta_max
217+
else:
218+
# Unfortunately on non-Linux Github test machines the RSS values seem
219+
# to vary a lot, which causes spurious test failures. So for at least
220+
# we don't actually check.
221+
#
222+
print(f'Not checking results because non-Linux behaviour is too variable.')

0 commit comments

Comments
 (0)