(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestClientSyncAutoUnsub(t *testing.T) { |
| 76 | s := RunDefaultServer() |
| 77 | defer s.Shutdown() |
| 78 | |
| 79 | nc := NewDefaultConnection(t) |
| 80 | defer nc.Close() |
| 81 | received := 0 |
| 82 | max := 10 |
| 83 | sub, _ := nc.SubscribeSync("foo") |
| 84 | sub.AutoUnsubscribe(max) |
| 85 | total := 100 |
| 86 | for range total { |
| 87 | nc.Publish("foo", []byte("Hello")) |
| 88 | } |
| 89 | nc.Flush() |
| 90 | for { |
| 91 | _, err := sub.NextMsg(10 * time.Millisecond) |
| 92 | if err != nil { |
| 93 | if err != nats.ErrMaxMessages { |
| 94 | t.Fatalf("Expected '%v', but got: '%v'\n", nats.ErrMaxMessages, err.Error()) |
| 95 | } |
| 96 | break |
| 97 | } |
| 98 | received++ |
| 99 | } |
| 100 | if received != max { |
| 101 | t.Fatalf("Received %d msgs, wanted only %d\n", received, max) |
| 102 | } |
| 103 | if sub.IsValid() { |
| 104 | t.Fatal("Expected subscription to be invalid after hitting max") |
| 105 | } |
| 106 | if err := sub.AutoUnsubscribe(10); err == nil { |
| 107 | t.Fatal("Calling AutoUnsubscribe() ob closed subscription should fail") |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | func TestClientChanAutoUnsub(t *testing.T) { |
| 112 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected