MCPcopy
hub / github.com/cloudflare/cloudflared / TestObserverEventsDontBlock

Function TestObserverEventsDontBlock

connection/observer_test.go:65–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func 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
89type eventCollectorSink struct {
90 observedEvents []Event

Callers

nothing calls this directly

Calls 5

RegisterSinkMethod · 0.95
sendRegisteringEventMethod · 0.95
NewObserverFunction · 0.85
EventSinkFuncFuncType · 0.85
StopMethod · 0.45

Tested by

no test coverage detected