(t *testing.T)
| 109 | } |
| 110 | |
| 111 | func TestClientChanAutoUnsub(t *testing.T) { |
| 112 | s := RunDefaultServer() |
| 113 | defer s.Shutdown() |
| 114 | |
| 115 | nc := NewDefaultConnection(t) |
| 116 | defer nc.Close() |
| 117 | received := 0 |
| 118 | max := 10 |
| 119 | ch := make(chan *nats.Msg, max) |
| 120 | sub, _ := nc.ChanSubscribe("foo", ch) |
| 121 | sub.AutoUnsubscribe(max) |
| 122 | total := 100 |
| 123 | for range total { |
| 124 | nc.Publish("foo", []byte("Hello")) |
| 125 | } |
| 126 | nc.Flush() |
| 127 | |
| 128 | // Drain the channel |
| 129 | for { |
| 130 | select { |
| 131 | case <-ch: |
| 132 | received++ |
| 133 | case <-time.After(10 * time.Millisecond): |
| 134 | if received != max { |
| 135 | t.Fatalf("Received %d msgs, wanted only %d", received, max) |
| 136 | } |
| 137 | if sub.IsValid() { |
| 138 | t.Fatal("Expected subscription to be invalid after hitting max") |
| 139 | } |
| 140 | if err := sub.AutoUnsubscribe(10); err == nil { |
| 141 | t.Fatal("Calling AutoUnsubscribe() ob closed subscription should fail") |
| 142 | } |
| 143 | return |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | } |
| 148 | |
| 149 | func TestClientASyncAutoUnsub(t *testing.T) { |
| 150 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected