subscriber_test.go 604 B

123456789101112131415161718192021222324252627282930313233
  1. package test
  2. import (
  3. "testing"
  4. "time"
  5. . "m7s.live/engine/v4"
  6. )
  7. type SlowSubsciber struct {
  8. Subscriber
  9. }
  10. func (s *SlowSubsciber) OnEvent(event any) {
  11. switch event.(type) {
  12. case AudioFrame:
  13. case VideoFrame:
  14. // 模拟慢消费,导致长时间占用后被发布者移除
  15. time.Sleep(1000 * time.Millisecond)
  16. default:
  17. s.Subscriber.OnEvent(event)
  18. }
  19. }
  20. func TestSlowSubscriber(t *testing.T) {
  21. t.Cleanup(FreeEngine)
  22. UseEngine()
  23. var pub UnitTestPublisher
  24. unitTestPlugin.Publish("test/slow", &pub)
  25. var suber SlowSubsciber
  26. unitTestPlugin.Subscribe("test/slow", &suber)
  27. suber.PlayRaw()
  28. }