MCPcopy
hub / github.com/nats-io/nats.go / TestRecvChanMultipleMessages

Function TestRecvChanMultipleMessages

test/netchan_test.go:304–332  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

302}
303
304func TestRecvChanMultipleMessages(t *testing.T) {
305 // Make sure we can receive more than one message.
306 // In response to #25, which is a bug from fixing #22.
307
308 s := RunDefaultServer()
309 defer s.Shutdown()
310
311 ec := NewEConn(t)
312 defer ec.Close()
313
314 // Num to send, should == len of messages queued.
315 size := 10
316
317 ch := make(chan int, size)
318
319 if _, err := ec.BindRecvChan("foo", ch); err != nil {
320 t.Fatalf("Failed to bind to a send channel: %v\n", err)
321 }
322
323 for i := 0; i < size; i++ {
324 ec.Publish("foo", 22)
325 }
326 ec.Flush()
327 time.Sleep(10 * time.Millisecond)
328
329 if lch := len(ch); lch != size {
330 t.Fatalf("Expected %d messages queued, got %d.", size, lch)
331 }
332}
333
334func BenchmarkPublishSpeedViaChan(b *testing.B) {
335 b.StopTimer()

Callers

nothing calls this directly

Calls 7

NewEConnFunction · 0.85
BindRecvChanMethod · 0.80
FatalfMethod · 0.80
RunDefaultServerFunction · 0.70
PublishMethod · 0.65
CloseMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected