(t *testing.T)
| 147 | } |
| 148 | |
| 149 | func TestClientASyncAutoUnsub(t *testing.T) { |
| 150 | s := RunDefaultServer() |
| 151 | defer s.Shutdown() |
| 152 | |
| 153 | nc := NewDefaultConnection(t) |
| 154 | defer nc.Close() |
| 155 | received := int32(0) |
| 156 | max := int32(10) |
| 157 | sub, err := nc.Subscribe("foo", func(_ *nats.Msg) { |
| 158 | atomic.AddInt32(&received, 1) |
| 159 | }) |
| 160 | if err != nil { |
| 161 | t.Fatal("Failed to subscribe: ", err) |
| 162 | } |
| 163 | sub.AutoUnsubscribe(int(max)) |
| 164 | total := 100 |
| 165 | for range total { |
| 166 | nc.Publish("foo", []byte("Hello")) |
| 167 | } |
| 168 | nc.Flush() |
| 169 | time.Sleep(10 * time.Millisecond) |
| 170 | |
| 171 | if atomic.LoadInt32(&received) != max { |
| 172 | t.Fatalf("Received %d msgs, wanted only %d\n", received, max) |
| 173 | } |
| 174 | if err := sub.AutoUnsubscribe(10); err == nil { |
| 175 | t.Fatal("Calling AutoUnsubscribe() on closed subscription should fail") |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | func TestAutoUnsubAndReconnect(t *testing.T) { |
| 180 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected