Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8KB

  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. }