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

Function TestSimpleSendChan

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

Source from the content-addressed store, hash-verified

56}
57
58func TestSimpleSendChan(t *testing.T) {
59 s := RunDefaultServer()
60 defer s.Shutdown()
61
62 ec := NewEConn(t)
63 defer ec.Close()
64
65 recv := make(chan bool)
66
67 numSent := int32(22)
68 ch := make(chan int32)
69
70 if err := ec.BindSendChan("foo", ch); err != nil {
71 t.Fatalf("Failed to bind to a send channel: %v\n", err)
72 }
73
74 ec.Subscribe("foo", func(num int32) {
75 if num != numSent {
76 t.Fatalf("Failed to receive correct value: %d vs %d\n", num, numSent)
77 }
78 recv <- true
79 })
80
81 // Send to 'foo'
82 ch <- numSent
83
84 if e := Wait(recv); e != nil {
85 if ec.LastError() != nil {
86 e = ec.LastError()
87 }
88 t.Fatalf("Did not receive the message: %s", e)
89 }
90 close(ch)
91}
92
93func TestFailedChannelSend(t *testing.T) {
94 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 8

NewEConnFunction · 0.85
BindSendChanMethod · 0.80
FatalfMethod · 0.80
RunDefaultServerFunction · 0.70
WaitFunction · 0.70
SubscribeMethod · 0.65
CloseMethod · 0.45
LastErrorMethod · 0.45

Tested by

no test coverage detected