feat(perf): Implement performance threshold alert system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import unittest
|
||||
import time
|
||||
from unittest.mock import MagicMock
|
||||
from performance_monitor import PerformanceMonitor
|
||||
|
||||
class TestPerformanceMonitor(unittest.TestCase):
|
||||
@@ -33,5 +34,18 @@ class TestPerformanceMonitor(unittest.TestCase):
|
||||
self.assertGreaterEqual(metrics['input_lag_ms'], 20)
|
||||
self.assertLess(metrics['input_lag_ms'], 40)
|
||||
|
||||
def test_alerts_triggering(self):
|
||||
mock_callback = MagicMock()
|
||||
self.monitor.alert_callback = mock_callback
|
||||
self.monitor.thresholds['frame_time_ms'] = 5.0 # Low threshold
|
||||
self.monitor._alert_cooldown = 0 # No cooldown for test
|
||||
|
||||
self.monitor.start_frame()
|
||||
time.sleep(0.01) # 10ms > 5ms
|
||||
self.monitor.end_frame()
|
||||
|
||||
mock_callback.assert_called_once()
|
||||
self.assertIn("Frame time high", mock_callback.call_args[0][0])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user