conductor(checkpoint): Checkpoint end of Phase 2: Test Suite Migration
This commit is contained in:
@@ -1,51 +1,29 @@
|
||||
import unittest
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
# Ensure project root is in path
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from performance_monitor import PerformanceMonitor
|
||||
|
||||
class TestPerformanceMonitor(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.monitor = PerformanceMonitor()
|
||||
def test_perf_monitor_basic_timing():
|
||||
pm = PerformanceMonitor()
|
||||
pm.start_frame()
|
||||
time.sleep(0.02) # 20ms
|
||||
pm.end_frame()
|
||||
|
||||
metrics = pm.get_metrics()
|
||||
assert metrics['last_frame_time_ms'] >= 20.0
|
||||
pm.stop()
|
||||
|
||||
def test_frame_time_collection(self):
|
||||
# Simulate frames for 1.1 seconds to trigger FPS calculation
|
||||
start = time.time()
|
||||
while time.time() - start < 1.1:
|
||||
self.monitor.start_frame()
|
||||
time.sleep(0.01) # ~100 FPS
|
||||
self.monitor.end_frame()
|
||||
|
||||
metrics = self.monitor.get_metrics()
|
||||
self.assertAlmostEqual(metrics['last_frame_time_ms'], 10, delta=10)
|
||||
self.assertGreater(metrics['fps'], 0)
|
||||
|
||||
def test_cpu_usage_collection(self):
|
||||
metrics = self.monitor.get_metrics()
|
||||
self.assertIn('cpu_percent', metrics)
|
||||
self.assertIsInstance(metrics['cpu_percent'], float)
|
||||
|
||||
def test_input_lag_collection(self):
|
||||
self.monitor.start_frame()
|
||||
self.monitor.record_input_event()
|
||||
time.sleep(0.02) # 20ms lag
|
||||
self.monitor.end_frame()
|
||||
|
||||
metrics = self.monitor.get_metrics()
|
||||
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()
|
||||
def test_perf_monitor_component_timing():
|
||||
pm = PerformanceMonitor()
|
||||
pm.start_component("test_comp")
|
||||
time.sleep(0.01)
|
||||
pm.end_component("test_comp")
|
||||
|
||||
metrics = pm.get_metrics()
|
||||
assert metrics['time_test_comp_ms'] >= 10.0
|
||||
pm.stop()
|
||||
|
||||
Reference in New Issue
Block a user