summary refs log tree commit diff
path: root/tests/metrics/test_background_process_metrics.py
blob: f0f6cb2912809981637ccc50a9eb620d4079d405 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from unittest import TestCase as StdlibTestCase
from unittest.mock import Mock

from synapse.logging.context import ContextResourceUsage, LoggingContext
from synapse.metrics.background_process_metrics import _BackgroundProcess


class TestBackgroundProcessMetrics(StdlibTestCase):
    def test_update_metrics_with_negative_time_diff(self) -> None:
        """We should ignore negative reported utime and stime differences"""
        usage = ContextResourceUsage()
        usage.ru_stime = usage.ru_utime = -1.0

        mock_logging_context = Mock(spec=LoggingContext)
        mock_logging_context.get_resource_usage.return_value = usage

        process = _BackgroundProcess("test process", mock_logging_context)
        # Should not raise
        process.update_metrics()