增加可选性能埋点并完成物性效率评估
This commit is contained in:
1 parent
4e0b9fd8cc
commit
57b459bc72
21 files changed
+2029
-179
No files matched your search
@@ -0,0 +1,58 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app.simulation.benchmark_performance import (
|
||||
_duration_summary,
|
||||
_load_factory_xml,
|
||||
_named_value,
|
||||
_serialize_result_event,
|
||||
)
|
||||
|
||||
|
||||
def sample_xml_factory() -> bytes:
|
||||
return b"<System/>"
|
||||
|
||||
|
||||
class PerformanceBenchmarkToolTests(unittest.TestCase):
|
||||
def test_named_value_requires_an_explicit_name(self) -> None:
|
||||
self.assertEqual(
|
||||
_named_value("chain=tests.example:project", option="--factory"),
|
||||
("chain", "tests.example:project"),
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "NAME=VALUE"):
|
||||
_named_value("tests.example:project", option="--factory")
|
||||
|
||||
def test_duration_summary_reports_repeatable_order_statistics(self) -> None:
|
||||
summary = _duration_summary([5.0, 1.0, 3.0, 2.0, 4.0])
|
||||
|
||||
self.assertEqual(summary["minimumMs"], 1.0)
|
||||
self.assertEqual(summary["medianMs"], 3.0)
|
||||
self.assertEqual(summary["p95Ms"], 5.0)
|
||||
self.assertEqual(summary["maximumMs"], 5.0)
|
||||
|
||||
def test_factory_loader_accepts_a_bytes_factory(self) -> None:
|
||||
self.assertEqual(
|
||||
_load_factory_xml(
|
||||
"tests.test_performance_benchmark:sample_xml_factory"
|
||||
),
|
||||
b"<System/>",
|
||||
)
|
||||
|
||||
def test_result_event_serialization_uses_ndjson_shape(self) -> None:
|
||||
payload = _serialize_result_event(
|
||||
{
|
||||
"success": True,
|
||||
"status": "completed",
|
||||
"simulatedUntil": 1.0,
|
||||
"requestedStopTime": 1.0,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertTrue(payload.endswith(b"\n"))
|
||||
self.assertIn(b'"event":"result"', payload)
|
||||
self.assertIn(b'"result":{"success":true', payload)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user