(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func TestObserverEventsDontBlock(t *testing.T) { |
| 66 | observer := NewObserver(&log, &log) |
| 67 | var mu sync.Mutex |
| 68 | observer.RegisterSink(EventSinkFunc(func(_ Event) { |
| 69 | // callback will block if lock is already held |
| 70 | mu.Lock() |
| 71 | mu.Unlock() |
| 72 | })) |
| 73 | |
| 74 | timeout := time.AfterFunc(5*time.Second, func() { |
| 75 | mu.Unlock() // release the callback on timer expiration |
| 76 | t.Fatal("observer is blocked") |
| 77 | }) |
| 78 | |
| 79 | mu.Lock() // block the callback |
| 80 | for i := 0; i < 2*observerChannelBufferSize; i++ { |
| 81 | observer.sendRegisteringEvent(0) |
| 82 | } |
| 83 | if pending := timeout.Stop(); pending { |
| 84 | // release the callback if timer hasn't expired yet |
| 85 | mu.Unlock() |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | type eventCollectorSink struct { |
| 90 | observedEvents []Event |
nothing calls this directly
no test coverage detected