2020-03-26 05:50:00 +00:00
|
|
|
import gc
|
|
|
|
import sys
|
|
|
|
|
2021-04-01 23:03:49 +00:00
|
|
|
from pyo3_pytests.objstore import ObjStore
|
2020-03-26 05:50:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_objstore_doesnot_leak_memory():
|
|
|
|
N = 10000
|
|
|
|
message = b'\\(-"-;) Praying that memory leak would not happen..'
|
2021-07-18 18:30:30 +00:00
|
|
|
|
|
|
|
# PyPy does not have sys.getrefcount, provide a no-op lambda and don't
|
|
|
|
# check refcount on PyPy
|
|
|
|
getrefcount = getattr(sys, "getrefcount", lambda obj: 0)
|
|
|
|
|
|
|
|
before = getrefcount(message)
|
2020-03-26 05:50:00 +00:00
|
|
|
store = ObjStore()
|
|
|
|
for _ in range(N):
|
|
|
|
store.push(message)
|
|
|
|
del store
|
|
|
|
gc.collect()
|
2021-07-18 18:30:30 +00:00
|
|
|
after = getrefcount(message)
|
2020-03-26 05:50:00 +00:00
|
|
|
|
|
|
|
assert after - before == 0
|