Test Failed
Push — master ( ae3125...7a2ee5 )
by Nicolas
02:38
created

test_memoryleak   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_memoryleak_no_history() 0 24 3
1
#!/usr/bin/env python
2
#
3
# Glances - An eye on your system
4
#
5
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <[email protected]>
6
#
7
# SPDX-License-Identifier: LGPL-3.0-only
8
#
9
10
"""Glances unitary tests suite for Glances memory leak."""
11
12
import time
13
import tracemalloc
14
15
16
def test_memoryleak_no_history(glances_stats_no_history, logger):
17
    """
18
    Test Glances memory leak.
19
    """
20
    tracemalloc.start()
21
    # First iterations just to init the stats and fill the memory
22
    logger.info('Please wait during memory leak test initialisation')
23
    iteration = 3
24
    for _ in range(iteration):
25
        glances_stats_no_history.update()
26
        time.sleep(1)
27
28
    # Then iteration to measure memory leak
29
    logger.info('Please wait during memory leak test')
30
    iteration = 10
31
    snapshot_begin = tracemalloc.take_snapshot()
32
    for _ in range(iteration):
33
        glances_stats_no_history.update()
34
        time.sleep(1)
35
    snapshot_end = tracemalloc.take_snapshot()
36
    snapshot_diff = snapshot_end.compare_to(snapshot_begin, 'filename')
37
    memory_leak = sum([s.size_diff for s in snapshot_diff]) // iteration
38
    logger.info(f'Memory consume per iteration: {memory_leak} bytes')
39
    assert memory_leak < 15000, f'Memory leak: {memory_leak} bytes'
40