cluster4npu/tests/unit/test_bottleneck.py
abin 55040733fe feat: implement Phase 1-4 performance visualization and device management
Phase 1 — Performance Benchmarking:
- PerformanceBenchmarker: sequential vs parallel benchmark with injectable runner
- PerformanceHistory: JSON-backed benchmark history with regression support
- PerformanceDashboard: real-time FPS/latency display widget
- BenchmarkDialog: one-click benchmark with 3-phase progress bar

Phase 2 — Device Management:
- DeviceManager: NPU dongle scan, assign/unassign, load balance recommendation
- DeviceManagementPanel: live device status cards with auto-refresh
- BottleneckAlert: dataclass for pipeline bottleneck detection

Phase 3 — Advanced Features:
- OptimizationEngine: 3 optimization rules (rebalance/adjust_queue/add_devices)
- TemplateManager: 3 built-in pipeline templates (YOLOv5, fire detection, dual-model)

Phase 4 — Report Export:
- ReportExporter: PDF (reportlab, optional) and CSV export
- ExportReportDialog: format selection + path picker UI

192 unit tests, all passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 19:32:05 +08:00

44 lines
1.3 KiB
Python

"""
tests/unit/test_bottleneck.py
Unit tests for the BottleneckAlert dataclass.
TDD: Red phase — tests written before implementation.
"""
import pytest
from core.device.bottleneck import BottleneckAlert
class TestBottleneckAlert:
def test_fields_accessible(self):
alert = BottleneckAlert(
stage_id="stage-1",
queue_fill_rate=0.85,
suggested_action="Add more Dongles to this stage",
severity="warning",
)
assert alert.stage_id == "stage-1"
assert alert.queue_fill_rate == 0.85
assert alert.suggested_action == "Add more Dongles to this stage"
assert alert.severity == "warning"
def test_severity_critical(self):
alert = BottleneckAlert(
stage_id="stage-2",
queue_fill_rate=0.95,
suggested_action="Urgent: add Dongles",
severity="critical",
)
assert alert.severity == "critical"
def test_dataclass_equality(self):
a = BottleneckAlert("s1", 0.9, "action", "warning")
b = BottleneckAlert("s1", 0.9, "action", "warning")
assert a == b
def test_dataclass_inequality(self):
a = BottleneckAlert("s1", 0.9, "action", "warning")
b = BottleneckAlert("s1", 0.5, "action", "warning")
assert a != b