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

Function TestCloseChanOnSubscriber

test/sub_test.go:1103–1127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1101}
1102
1103func TestCloseChanOnSubscriber(t *testing.T) {
1104 s := RunDefaultServer()
1105 defer s.Shutdown()
1106
1107 nc := NewDefaultConnection(t)
1108 defer nc.Close()
1109
1110 // Create our own channel.
1111 ch := make(chan *nats.Msg, 8)
1112 nc.ChanSubscribe("foo", ch)
1113
1114 // Send some messages to ourselves.
1115 total := 100
1116 for range total {
1117 nc.Publish("foo", []byte("Hello"))
1118 }
1119
1120 nc.Close()
1121 for len(ch) > 0 {
1122 <-ch
1123 }
1124 // Make sure we can send to the channel still.
1125 // Test that we do not close it.
1126 ch <- &nats.Msg{}
1127}
1128
1129func TestAsyncSubscriptionPending(t *testing.T) {
1130 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 5

RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
ChanSubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected