test_background_process_metrics.py 774 B

12345678910111213141516171819
  1. from unittest import TestCase as StdlibTestCase
  2. from unittest.mock import Mock
  3. from synapse.logging.context import ContextResourceUsage, LoggingContext
  4. from synapse.metrics.background_process_metrics import _BackgroundProcess
  5. class TestBackgroundProcessMetrics(StdlibTestCase):
  6. def test_update_metrics_with_negative_time_diff(self) -> None:
  7. """We should ignore negative reported utime and stime differences"""
  8. usage = ContextResourceUsage()
  9. usage.ru_stime = usage.ru_utime = -1.0
  10. mock_logging_context = Mock(spec=LoggingContext)
  11. mock_logging_context.get_resource_usage.return_value = usage
  12. process = _BackgroundProcess("test process", mock_logging_context)
  13. # Should not raise
  14. process.update_metrics()