test_live_uds.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Live UDS tests against a running hthd. Skipped unless HTH_OBSERVE_SOCK is set."""
  2. from __future__ import annotations
  3. import asyncio
  4. import os
  5. from datetime import timedelta
  6. import pytest
  7. from hth_sdk.client import connect
  8. from hth_sdk.profiles import prod2u
  9. pytestmark = pytest.mark.skipif(
  10. not os.environ.get("HTH_OBSERVE_SOCK"),
  11. reason="HTH_OBSERVE_SOCK not set",
  12. )
  13. async def _run() -> None:
  14. observe = os.environ["HTH_OBSERVE_SOCK"]
  15. control = os.environ.get("HTH_CONTROL_SOCK") or None
  16. role = "control" if control else "observe"
  17. async with await connect(observe=observe, control=control, role=role) as client:
  18. caps = await client.get_capabilities("prod2u-0")
  19. assert caps.api_version == "hth.api.v1"
  20. assert caps.ack_supported is False
  21. assert caps.position_feedback_supported is False
  22. snap = await client.get_snapshot("prod2u-0")
  23. assert snap.snapshot_seq >= 1
  24. n = 0
  25. async for s in client.subscribe_telemetry("prod2u-0"):
  26. n += 1
  27. if s.data_gap:
  28. assert s.dropped_count >= 1
  29. if n >= 2:
  30. break
  31. if control:
  32. async with await client.acquire_lease(
  33. "prod2u-0", "pytest-live", timedelta(seconds=5), auto_renew=False
  34. ) as lease:
  35. snap = await client.get_snapshot("prod2u-0")
  36. batch = (
  37. prod2u.builder("prod2u-0", capabilities=caps)
  38. .based_on(snap.snapshot_seq, snap.control_revision)
  39. .set_fan(1, 10)
  40. .set_ptc(1, 0)
  41. .set_door_close_percent("x", 0)
  42. .set_door_close_percent("y", 0)
  43. .set_door_close_percent("z", 0)
  44. .build()
  45. )
  46. res = await lease.apply(batch)
  47. assert res.confirmation != "CONFIRMED"
  48. def test_live_uds_mock_daemon() -> None:
  49. asyncio.run(_run())