Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

83 строки
2.6KB

  1. package app
  2. import (
  3. "testing"
  4. cfgpkg "github.com/jan/fm-rds-tx/internal/config"
  5. "github.com/jan/fm-rds-tx/internal/output"
  6. "github.com/jan/fm-rds-tx/internal/platform"
  7. )
  8. func TestEngineRuntimeStateReporting(t *testing.T) {
  9. e := NewEngine(cfgpkg.Default(), platform.NewSimulatedDriver(nil))
  10. if got := e.Stats().State; got != string(RuntimeStateIdle) {
  11. t.Fatalf("expected initial state idle, got %s", got)
  12. }
  13. e.setRuntimeState(RuntimeStatePrebuffering)
  14. if got := e.Stats().State; got != string(RuntimeStatePrebuffering) {
  15. t.Fatalf("expected prebuffering, got %s", got)
  16. }
  17. e.setRuntimeState(RuntimeStateRunning)
  18. if got := e.currentRuntimeState(); got != RuntimeStateRunning {
  19. t.Fatalf("currentRuntimeState mismatch: %s", got)
  20. }
  21. }
  22. func TestEngineRuntimeStateTransitions(t *testing.T) {
  23. e := NewEngine(cfgpkg.Default(), platform.NewSimulatedDriver(nil))
  24. e.setRuntimeState(RuntimeStatePrebuffering)
  25. queue := output.QueueStats{Depth: 1, FillLevel: 0.75, Health: output.QueueHealthNormal}
  26. e.evaluateRuntimeState(queue, false)
  27. if got := e.currentRuntimeState(); got != RuntimeStateRunning {
  28. t.Fatalf("expected running after full buffer, got %s", got)
  29. }
  30. queue.Health = output.QueueHealthCritical
  31. for i := 0; i < queueCriticalStreakThreshold; i++ {
  32. e.evaluateRuntimeState(queue, false)
  33. }
  34. if got := e.currentRuntimeState(); got != RuntimeStateDegraded {
  35. t.Fatalf("expected degraded on queue critical streak, got %s", got)
  36. }
  37. queue.Health = output.QueueHealthNormal
  38. e.evaluateRuntimeState(queue, false)
  39. if got := e.currentRuntimeState(); got != RuntimeStateRunning {
  40. t.Fatalf("expected running once queue healthy, got %s", got)
  41. }
  42. e.evaluateRuntimeState(queue, true)
  43. if got := e.currentRuntimeState(); got != RuntimeStateDegraded {
  44. t.Fatalf("expected degraded when late buffers seen, got %s", got)
  45. }
  46. }
  47. func TestEngineRuntimeStateMuteOnPersistentQueueCritical(t *testing.T) {
  48. e := NewEngine(cfgpkg.Default(), platform.NewSimulatedDriver(nil))
  49. e.setRuntimeState(RuntimeStateRunning)
  50. queue := output.QueueStats{Depth: 1, Health: output.QueueHealthCritical}
  51. for i := 0; i < queueMutedStreakThreshold; i++ {
  52. e.evaluateRuntimeState(queue, false)
  53. }
  54. if got := e.currentRuntimeState(); got != RuntimeStateMuted {
  55. t.Fatalf("expected muted after prolonged queue critical, got %s", got)
  56. }
  57. last := e.LastFault()
  58. if last == nil {
  59. t.Fatal("expected fault recorded for the mute transition")
  60. }
  61. if last.Reason != FaultReasonQueueCritical {
  62. t.Fatalf("expected queue critical reason, got %s", last.Reason)
  63. }
  64. if last.Severity != FaultSeverityMuted {
  65. t.Fatalf("expected muted severity, got %s", last.Severity)
  66. }
  67. }