aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/lz4/py2/tests/block/test_block_3.py
blob: 0c3fb0821d3d4dbe42cb25545a9e74a0a934148f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import lz4.block
import pytest


test_data = [
    (b'a' * 1024 * 1024),
]


@pytest.fixture(
    params=test_data,
    ids=[
        'data' + str(i) for i in range(len(test_data))
    ]
)
def data(request):
    return request.param


def test_block_decompress_mem_usage(data):
    tracemalloc = pytest.importorskip('tracemalloc')

    tracemalloc.start()

    compressed = lz4.block.compress(data)
    prev_snapshot = None

    for i in range(1000):
        decompressed = lz4.block.decompress(compressed)  # noqa: F841

        if i % 100 == 0:
            snapshot = tracemalloc.take_snapshot()

            if prev_snapshot:
                stats = snapshot.compare_to(prev_snapshot, 'lineno')
                assert stats[0].size_diff < (1024 * 4)

            prev_snapshot = snapshot