MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestSubscribeAsync

Function TestSubscribeAsync

chainbus/bus_test.go:147–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestSubscribeAsync(t *testing.T) {
148 results := make(chan int)
149
150 bus := New()
151 bus.SubscribeAsync("/event/test", func(a int, out chan<- int) {
152 out <- a
153 }, false)
154
155 bus.Publish("/event/test", 1, results)
156 bus.Publish("/event/test", 2, results)
157
158 var numResults int32
159
160 go func() {
161 for range results {
162 atomic.AddInt32(&numResults, 1)
163 }
164 }()
165
166 bus.WaitAsync()
167
168 time.Sleep(10 * time.Millisecond)
169
170 if atomic.LoadInt32(&numResults) != 2 {
171 t.Fail()
172 }
173}

Callers

nothing calls this directly

Calls 4

NewFunction · 0.70
SubscribeAsyncMethod · 0.65
PublishMethod · 0.65
WaitAsyncMethod · 0.65

Tested by

no test coverage detected