camera_stream_status_test.go 713 B

1234567891011121314151617181920212223242526
  1. package parking
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestRecentCameraStreamFrameMarksCameraOnline(t *testing.T) {
  7. deviceCode := "camera-stream-status-test"
  8. cameraLastFrameAt.Delete(deviceCode)
  9. t.Cleanup(func() { cameraLastFrameAt.Delete(deviceCode) })
  10. if hasRecentCameraStreamFrame(deviceCode) {
  11. t.Fatal("camera without video output must be offline")
  12. }
  13. markCameraStreamFrame(deviceCode)
  14. if !hasRecentCameraStreamFrame(deviceCode) {
  15. t.Fatal("camera with recent video output must be online")
  16. }
  17. cameraLastFrameAt.Store(deviceCode, time.Now().Add(-cameraStreamOnlineTTL-time.Millisecond))
  18. if hasRecentCameraStreamFrame(deviceCode) {
  19. t.Fatal("camera with expired video output must be offline")
  20. }
  21. }