(t *testing.T)
| 1072 | } |
| 1073 | |
| 1074 | func TestUnsubscribeChanOnSubscriber(t *testing.T) { |
| 1075 | s := RunDefaultServer() |
| 1076 | defer s.Shutdown() |
| 1077 | |
| 1078 | nc := NewDefaultConnection(t) |
| 1079 | defer nc.Close() |
| 1080 | |
| 1081 | // Override default handler for test. |
| 1082 | nc.SetErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, _ error) {}) |
| 1083 | |
| 1084 | // Create our own channel. |
| 1085 | ch := make(chan *nats.Msg, 8) |
| 1086 | sub, _ := nc.ChanSubscribe("foo", ch) |
| 1087 | |
| 1088 | // Send some messages to ourselves. |
| 1089 | total := 100 |
| 1090 | for range total { |
| 1091 | nc.Publish("foo", []byte("Hello")) |
| 1092 | } |
| 1093 | |
| 1094 | sub.Unsubscribe() |
| 1095 | for len(ch) > 0 { |
| 1096 | <-ch |
| 1097 | } |
| 1098 | // Make sure we can send to the channel still. |
| 1099 | // Test that we do not close it. |
| 1100 | ch <- &nats.Msg{} |
| 1101 | } |
| 1102 | |
| 1103 | func TestCloseChanOnSubscriber(t *testing.T) { |
| 1104 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected