@@ -199,24 +199,24 @@ def get_stat():
199
199
gc .collect ()
200
200
get_stat ()
201
201
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 = } ' )
205
205
pv = platform .python_version_tuple ()
206
206
pv = (int (pv [0 ]), int (pv [1 ]))
207
207
if pv < (3 , 11 ):
208
208
# 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.' )
212
210
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 = } '
217
213
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