summary refs log tree commit diff
path: root/tests/metrics/test_background_process_metrics.py
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2022-10-31 13:02:07 +0000
committerGitHub <noreply@github.com>2022-10-31 13:02:07 +0000
commit2bb2c32e8ed5642a5bf3ba1e8c49e10cecc88905 (patch)
treeb25c0eb8017de0c12dc176dbae2679d9177c0cbf /tests/metrics/test_background_process_metrics.py
parentPrevent federation user keys query from returning device names if disallowed ... (diff)
downloadsynapse-2bb2c32e8ed5642a5bf3ba1e8c49e10cecc88905.tar.xz
Avoid incrementing bg process utime/stime counters by negative durations (#14323)
Diffstat (limited to 'tests/metrics/test_background_process_metrics.py')
-rw-r--r--tests/metrics/test_background_process_metrics.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/metrics/test_background_process_metrics.py b/tests/metrics/test_background_process_metrics.py
new file mode 100644

index 0000000000..f0f6cb2912 --- /dev/null +++ b/tests/metrics/test_background_process_metrics.py
@@ -0,0 +1,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()